DetailsFragment Overridden Methods onCreateOptionsMenu and onOptionsItemSelected

The DetailsFragment’s menu provides options for editing the current contact and for deleting it. Method onCreateOptionsMenu (Fig. 8.48, lines 114–119) inflates the menu resource file fragment_details_menu.xml. Method onOptionsItemSelected (lines 122– 146) uses the selected MenuItem’s resource ID to determine which one was selected. If the user selected the menu item with ID R.id.action_edit, lines 129–137 create a Bundle containing the contact’s data, then line 138 passes the Bundle to the DetailsFragmentListener for use in the AddEditFragment. If the user selected the menu item with ID R.id.action_delete, line 141 calls method deleteContact (Fig. 8.50).

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.