How to open Menu Context Android with click button in listview adapter ?
I tried with my code, but not show the menu context,
code
The accepted answer is really not optimal - it may simply be dated.
button.setOnCreateContextMenuListener((menu, v, menuInfo) -> {
final MenuItem item = menu.add("item-text");
item.setOnMenuItemClickListener(i -> {
doWorkOnItemClick();
return true; // Signifies you have consumed this event, so propogation can stop.
});
final MenuItem anotherItem = menu.add("another-item");
anotherItem.setOnMenuItemClickListener(i -> doOtherWorkOnItemClick());
});
button.setOnClickListener(View::showContextMenu);
Alternatively you can show the context menu in a specific location like so:
button.setOnClickListener(view -> view.showContextMenu(x, y));