You can implement onContextItemSelected
in the same class as your onCreateContextMenu
but you'll need to give your menu items IDs, so replace
menu.add("Call")
with something like
menu.add(MenuItem.NONE, CALL_ITEM_ID, MenuItem.NONE, "Call");
(The two NONE
s refer to grouping and ordering of items - see http://developer.android.com/reference/android/view/Menu.html#add(int, int, int, java.lang.CharSequence)
Then you can have
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case CALL_ITEM_ID:
doCallStuff();
...
Alternatively, menu.add()
returns a MenuItem
, to which you can add an OnMenuItemClickListener
, like this:
MenuItem callItem = menu.add("Call");
callItem.setOnMenuItemClickListener(new MenuItemOnClickListener() {
public boolean onMenuItemClick(MenuItem item) {
// do whatever you want to do...
doCallStuff();
// then return true to say you've handled this
return true;
}
});