You need to register your registerForContextMenu menu.
From this page
In order for a view to provide a context menu, you must "register" a context menu view. Call registerForContextMenu () and pass it the View you want to provide to the menu context. When this view then receives a long-press, it displays the menu context.
Your code above works fine. You just need to register a content menu to view it.
If you want to launch the context menu from anywhere on the screen:
Let's say your main.xml layout looks like this:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainLayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> </LinearLayout>
You will register the context menu that you created with the following (in onCreate ):
LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout); registerForContextMenu(layout);
So, if you run this in the emulator and make a long click on the Android desktop, your menu will appear.
source share