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