According to Android documentation registerForContextMenu can be called multiple times for different views:
Registers a context menu to be shown for the given view (multiple views can show the context menu).
I try to use this feature for the following layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/host"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:longClickable="true" >
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
In the source code I call registerForContextMenu both for the host and the list. Unfortunately, such registration leads to a problem: in the method onContextItemSelected(MenuItem item) I always get null for menu info requested through item.getMenuInfo(). Of course, the long touch is made on a list view item in this use case, so menu item should be normally not null. If I remove registerForContextMenu for the host layout, then menu info is provided correctly in the onContextItemSelected.
I need this multiple registration of the context menu in order to make sure it is shown for touches in any place on the screen (details can be found in another question – here). In brief, the context menu should appear for items and on touches outside any item, and if it is invoked for an item, I need to get the item position.
It”s not because you are using multiple registerForContextMenu, it’s because you set one on the view that contains the other. So all of them register as coming from the host and not the list.
And a regular view will have no extra menu info.
Try turning off focus for the host to let it.fall through to the list. It should still work for the host too, it just won’t grab focus before the list.