This hook is called whenever an item in a context menu is selected. The default implementation simply returns false to have the normal processing happen (calling the item's Runnable or sending a message to its Handler as appropriate). You can use this method for any items for which you would like to do processing without those other facilities. Use getMenuInfo() to get extra information set by the View that added this menu item.
Derived classes should call through to the base class for it to perform the default menu handling.
Parameter: item - The context menu item that was selected.
Returns: boolean - Return false to allow normal context menu processing to proceed, true to consume it here.
This is the method that is called when a context menu item is selected.
1. Make a Context Menu for a ListView Item
2. In the MainActivity.java file, add the onContextItemSelected method to the class.
@Override
public boolean onContextItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.myitem:
// do something. To test, Add a Toast
return true;
}
return super.onContextItemSelected(item);
}
3. Compile and run!
Resources:
http://developer.android.com/reference/android/app/Activity.html#onContextItemSelected(android.view.MenuItem)