-1

I have Listview. And I want to add overflow menu to each listview's item. How to do it? Now I add button to every item and show dropdown menu when user clicks on this button. But I want to replace this ordinary button with overflow one.

Junior222
  • 803
  • 3
  • 12
  • 22

1 Answers1

1
  1. Add an ImageView or Button to trigger the menu on the right of your listview items. To get the "overflow" icon, see this question: How do I get a copy of the Android overflow menu icon?
  2. Add an onClickListener to your ImageView or Button
  3. On your onCreate() method, create a popup menu like this:

    popupMenu = new PopupMenu(this, findViewById(R.id.anchor)); popupMenu.getMenu().add(...); popupMenu.setOnMenuItemClickListener(this);

  4. In your onClickListener trigger the display of the popup menu

    popupMenu.show();

Community
  • 1
  • 1
Quanturium
  • 5,698
  • 2
  • 30
  • 36