Responding to Context Menu Items

The third step in our implementation of a context menu is responding to context-menu clicks. The mechanism of responding to context menus is similar to the mechanism of responding to options menus. Android provides a callback method similar to onOptionsItemSelected() called onContextItemSelected(). This method, like its counterpart, is also available on the Activity class. Listing 5-17 demonstrates onContextItemSelected().

Listing 5-17. Responding to Context Menus ^Override public boolean onContextItemSelected(MenuItem item) {

//handle this menu item return true;

... other exception processing }

0 0

Post a comment