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, implement onCreateContextMenu(…) to inflate the menu ...

Get Android Programming: The Big Nerd Ranch Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.