Reputation: 3607
I am trying to add a context menu to a linear layout and open it on single click. The linear layout, in turn, contains a textview so that the listener can be invoked when user clicks anywhere on the layout.
Setting onClick listener to linear layout.
linearLayout.setOnClickListener(this);
And the onClick method:
public void onClick(View view) {
openContextMenu(view);
//view.showContextMenu(); // didn't work as well
}
the above method should trigger the following
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo){
super.onCreateContextMenu(menu, view, menuInfo);
menu.setHeaderTitle("Title");
menu.add(0, id, 0, "Item 1");
}
However, this seems to be not working. From other community posts in here, this is the solution I could possibly find. I wonder if I miss something.
Any thoughts?
Thanks in advance!
Upvotes: 3
Views: 5132
Reputation: 15973
Did you register the context menu for the linear layout using:
registerForContextMenu(linearLayout);
Upvotes: 2