O'Reilly logo

Android Programming: The Big Nerd Ranch Guide by Brian Hardy, Bill Phillips

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required