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:

 ​ ​ ​ ​p​u​b​l​i​c​ ​v​o​i​d​ ​o​n​C​r​e​a​t​e​C​o​n​t​e​x​t​M​e​n​u​(​C​o​n​t​e​x​t​M​e​n​u​ ​m​e​n​u​,​ ​V​i​e​w​ ​v​,​
 ​ ​ ​ ​ ​ ​ ​ ​C​o​n​t​e​x​t​M​e​n​u​.​C​o​n​t​e​x​t​M​e​n​u​I​n​f​o​ ​m​e​n​u​I​n​f​o​)​

To respond to the user’s context menu selection, you implement this Fragment method:

 ​ ​ ​ ​p​u​b​l​i​c​ ​b​o​o​l​e​a​n​ ​o​n​C​o​n​t​e​x​t​I​t​e​m​S​e​l​e​c​t​e​d​(​M​e​n​u​I​t​e​m​ ​i​t​e​m​)​

Creating the context menu

In CrimeListFragment.java, implement onCreateContextMenu(…) to inflate the menu ...

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.