Context-sensitive menus (context menu) are the menus that are displayed on the right mouse button on a PC, and are long pressed on the Android platform to activate the contextual Menu,context menu, which is typically used to display menus related to current UI content.
The use of context menu is very similar to option menu:
The first is to create a menu resource, a new menu_context_shape.xml under Res/menu to display the oval,pear,shape2d:
<?xml version= "1.0″encoding=" utf-8″?>
<menu
Xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item
Android:id= "@+id/mnuoval"
android:title= "Oval" >
</item>
<item
Android:id= "@+id/mnupear"
android:title= "Pear" >
</item>
<item
Android:id= "@+id/mnushape2ddemo"
android:title= "Shape2d" >
</item>
</menu>
Expand the context Menu by using the Oncreatecontextmenu method:
@Override
public void Oncreatecontextmenu (ContextMenu menu, View V,
Contextmenuinfo menuinfo) {
Super.oncreatecontextmenu (menu, V, menuinfo);
Menuinflater inflater = Getmenuinflater ();
Inflater.inflate (R.menu.menu_context_shape, menu);
}
To handle the context menu event:
@Override
public boolean oncontextitemselected (MenuItem item) {
Menuoption = Item.getitemid ();
DrawImage ();
return super.oncontextitemselected (item);
}
In order to display the context menu on the view in a long time, you need to register the context menu for view:
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Registerforcontextmenu (Graphic2dview);
}