Fill out the body of the onOptionsItemSelected() method:

This is going to handle our new "Add Note" menu item. When this is selected, the onOptionsItemSelected() method will be called with the item.getId() set to INSERT ID (the constant we used to identify the menu item). We can detect this, and take the appropriate actions:

1. The super.onOptionsItemSelected(item) method call goes at the end of this method — we want to catch our events first!

2. Write a switch statement on item.getItemId() .

In the case of INSERT_ID, call a new method, createNote() , and return true, because we have handled this event and do not want to propagate it through the system.

3. Return the result of the superclass' onOptionsItemSelected() method at the end. The whole onOptionsItemSelect() method should now look like this:

@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case INSERT_ID:

createNote(); return true;

return super.onOptionsItemSelected(item);

0 0

Post a comment