Android launches activity with intent by clicking the context menu

Source: Internet
Author: User

Programming small white One, title, how to do, I have now added a floating navigation menu in the app, I want to click on the navigation menu to start a new activity, but the following code can not be completed, please God to see

protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);     Setcontentview (R.layout.activity_activity_view);     DataSource = new Dbdatasource (this);     Datasource.open ();     Values = Datasource.getallmahasiswa (); arrayadapter<mahasiswa> adapter = new Arrayadapter<mahasiswa> (this, Android.     R.layout.simple_list_item_1, values);     Setlistadapter (adapter); listview= (ListView) Findviewbyid (Android.    R.id.list);   Registerforcontextmenu (ListView); }public void Oncreatecontextmenu (ContextMenu menu, View V, contextmenuinfo menuinfo) {Super.oncreatecontextmenu (Me         Nu, V, menuinfo);        Menu.add (0, 0, "Edit"); Menu.add (0, 1001, 0, "Hapus"); } public boolean oncontextmenuitemselected (MenuItem item) {switch (Item.getitemid ()) {case 1000:inte            NT i = new Intent (activityview.this, Tes.class);       StartActivity (i);       Break       Case 1001://not yet break;    }   return super.oncontextitemselected (item); }</mahasiswa></mahasiswa>


Processing methods

There are two ways to complete Android development, using the 2 code below
Code One
@Override
public boolean oncontextitemselected (MenuItem Item)
{
Switch (Item.getitemid ())
{
Case R.id.pick_camera:

Break
}
return super.oncontextitemselected (item);
}
Code two
@Override
public void Oncreatecontextmenu (ContextMenu menu, View V, Contextmenuinfo menuinfo)
{

Getmenuinflater (). Inflate (r.menu.image_options, menu);
Super.oncreatecontextmenu (menu, V, menuinfo);
}

Create Image_options.xml in menu resource path
Create Image_options.xml in Menu folder of resource.
<?xml version= "1.0" encoding= "Utf-8"?>
<menu xmlns:android= "Http://schemas.android.com/apk/res/android" >

<item
Android:id= "@+id/pick_camera"
android:title= "Use Camera" >
</item>

</menu>


Original address: http://www.itmmd.com/201411/149.html
This article by Meng Meng's IT person to organize the release, reprint must indicate the source.

Android launches activity with intent by clicking the context menu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.