I have a simple LinearLayout with ListView inside it (match_parent
both for width and height). I need a context menu to show up upon a long touch on ANY place in the ListView. First, I called registerForContextMenu
for the ListView. This makes the context menu show up ONLY if the touch is performed on a list item. Then I called registerForContextMenu
for the LinearLayout as well, and set it attribute android:longClickable="true"
. This did not help.
So the question is how can one produce a context menu for a long touch below list items? For example, if we have 1 item in the list view, there is a lot of empty space below the item. Why does it not used for context menu invocation, provided that the list view fills entire parent according to the layout?
I don't think that long clicking anywhere on the
ListView
to get aContextMenu
it's a normal behavior, one the user will expect(especially in your case, with the user clicking the empty space below theListView
and aListView
ContextMenu
would appear).Anyway, for your example, you can set your
ListView
height attribute towrap_content
(If I remember right, this is the recommended value) and then register theContextmenu
for theListView
and the parentLinearLayout
(of course you'll have to provide the same code for both).