Overridden Fragment Methods onCreateOptionsMenu and onOptionsItemSelected

Figure 7.18 overrides Fragment’s onCreateOptionsMenu method (lines 142–147) to add the options to the method’s Menu argument using the method’s MenuInflater argument. When the user selects a menu item, Fragment method onOptionsItemSelected (lines 150–180) responds to the selection.

141      // display this fragment's menu items142      @Override143      public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)144      {145         super.onCreateOptionsMenu(menu, inflater);146         inflater.inflate(R.menu.doodle_fragment_menu, menu);147      }148 149      // handle choice from options menu150      @Override151      public boolean ...

Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.