1

I currently have a button that generates a popup menu and I'm trying to find a way to detect when an item within the menu has been long clicked. Once I detect the user has clicked and held on the menu item I want to prompt them to ask if they wish to delete the item.

I understand how to programatically remove menu items, ala the post here: remove popup menu item programmatically. The problem i'm having is detecting the long click on a menu item.

As far as I know there is no setMenuOnItemLongClickListener(), only a setMenuOnItemClickListener(), so am I left to make a custom solution to detect long clicks on popupmenu items?

Community
  • 1
  • 1
Cody
  • 1,801
  • 3
  • 28
  • 53

1 Answers1

1

Set action view to menu items and get them via getActionView(). To this view you can attach long click listeners.

You can attach an action view to menu item through xml as well:

<item
    ...
    android:actionViewClass="<custom class>"
</item>
random
  • 10,238
  • 8
  • 57
  • 101
  • Could you kindly add a bit more code to describe how to set action view to menu items programatically? The menu's items are added during runtime so I have to set the action view programatically instead of via xml (and i'm not familiar with the process) – Cody Jan 01 '16 at 19:03
  • See if this helps http://stackoverflow.com/questions/5446126/custom-action-view-cant-be-clicked – random Jan 04 '16 at 07:25