Implementing a Floating Context Menu
You are going to build the floating context menu first. The Fragment callbacks are similar to those you used for the options menu in Chapter 16. You inflate a context menu using the following method:
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo)
To respond to the user’s context menu selection, you implement this Fragment method:
public boolean onContextItemSelected(MenuItem item)
Creating the context menu
In CrimeListFragment.java, implement onCreateContextMenu(…) to inflate the menu resource and use it to populate the context menu.
Listing 18.2 Creating the context menu (CrimeListFragment.java
)
@Override public boolean onOptionsItemSelected(MenuItem item) ...
Get Android Programming: The Big Nerd Ranch Guide 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.