Android: show option menu after touching button for 3 or 4 second

Issue

I want one option menu when I touch the button for 2 or 3 second in my application.
Example: In the Message Application when I touch particular message for 2 to 3 second then one option menu come which show:

Delete

copy

Lock

Forward

Copy to Sim

etc.
So how can I use this on my application.
Can I use

onOptionsItemSelected

this method.Or something else.

Here One more thing which I want, suppose in Context Menu Five Action is there and after selecting fifth action first action will disable and only enable when I select Fourth Action.
Suppose the cose is:

public void onCreateContextMenu(ContextMenu menu, View v,
        ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    menu.setHeaderTitle("Option Menu");
     menu.add(0, v.getId(), 0, "First Action");
     menu.add(0, v.getId(), 0, "Second Action");
     menu.add(0, v.getId(), 0, "Third Action");
    menu.add(0, v.getId(), 0, "Fourth Action");
    menu.add(0, v.getId(), 0, "Fifth Action");
}

now when I select Fifth Action then First Action will disable and only enable when I select Fourth Action.
Please Suggest me…

Solution

FYI, the menu which you are talking about is known as Context Menu, not an Option Menu.

More detailed example is given here: http://www.stealthcopter.com/blog/2010/04/android-context-menu-example-on-long-press-gridview/

Guidelines for Menu: http://developer.android.com/guide/topics/ui/menus.html

Once you are done with example, just implement OnLongClickListener to your button.

Answered By – Paresh Mayani

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published