Android ContextMenu Tutorial with Example

By | April 18, 2019

What is ContextMenu ?

ContextMenu is a floating menu.when user perform a long press on element and it is display to selected option of context menu. It affects the selected content while doing action on it.It doesn’t support item shortcuts and icons.

Windows os system when user right click to open refresh menu same like context menu when user long press to open menu and display item when user selected to item action performed.

Context menu need to register view on activity or fragment to used this method of registerForContextMenu(View) . And we need to override onCreateContextMenu() in our activity or fragments.

Implementation of ContextMenu

Create activity_main.xml file.

Create File

Now in this code i have used to list view and list of item add string.when user click of any item long press to open context menu dialog and selected any action item in context menu.