Android: Detecting Long Click on PopupMenu Items - java

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?

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>

Related

add Checkbox on Action Bar on other app to select all

I was able to make a checkbox button on menu bar and tick on it to selecting all items in my own app, it is possible to make checkbox on whatsapp menu and when tick marking on it, it will select all contacts on whatsapp?

How to stop Java FX (1.8) menu button items from being drawn over the menu button?

I have this really annoying problem with the Java FX menu button. I have an application that dynamically (at run time) adds items to the menu button menu. The menu button is positioned on the bottom of the screen and so the menu opens towards the top. The menu items are added at the bottom of the menu list. The problems is sometimes this causes the menu to be drawn over the menu button when it is clicked, eventually it will correct its self but since the menu has dynamic items it will happen repeatedly. Is there a way to force a recalculation of menu positions so when it opens it does not cover the menu button?
The diagram on the left is what I would like to have happen when the menu is opened. The diagram on the right is what actually happens when the menu is shown after adding a menu item (the whole menu is drawn on top of the menu button)

Custom cut/copy action menu for long press on text in android?

I have an app where I want to be able to show a TextView
that allows the user to select some text if a user selected some text need to display custom menu. Example: custom search and Google search... .
I can intercept long-press to show my own action menu like. Reference text::: An ActionBar is located at the top of an activity and it can display any number of status or navigation related elements such as title, icon, buttons, or arbitrary action-related views.
If I select text "An ActionBar is located at" Then I need a menu like that text need to search in Google search or Wikipedia search.
Need code for this requirement.

Search bar for searching

I want to create a search bar for my app. The app has many activities linked via buttons for each activity. I want a search bar to search for those buttons in order to open that activity. The search bar should be placed in the title bar. If searched for the text on the button only that button should be shown...plz help...new to android development
Use a list view with button effect instead of buttons. You can then filter the array list you are passing to the list view.

How to add click event on Android Action Bar

I have added one star icon on Action Bar. Now I want to add click event on that star. If the star is clicked then it should be bright or Turned ON which is OFF by default. And if that star is ON and clicked, then it should go to OFF. I am not getting any idea how to perform onClick event on action bar.
You have a good example here.
Action Bar Example
To add onClickListener to a view in your action bar you have to create a reference to that view first and then in the onCreateOptionsMenu() method you can register the onClickListener.
See the answer to this question here. Its the same principle, you're simply using a 'star icon' instead of a switch.

Categories

Resources