Responding to Menu Items Through Listeners

You usually respond to menus by overriding onOptionsItemSelected; this is the recommended technique for better performance. However, a menu item allows you to register a listener that could be used as a callback.

This approach is a two-step process. In the first step, you implement the OnMenuClickListener interface. Then you take an instance of this implementation and pass it to the menu item. When the menu item is clicked, the menu item will call the onMenuItemClick() method of the OnMenuClickListener interface (see Listing 5-5).

Listing 5-5. Using a Listener as a Callback for a Menu-Item Click //Step 1

public class MyResponse implements OnMenuClickListener {

//Some constructors ^override

0 0

Post a comment