Vinit ...
Vinit ...

Reputation: 1459

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

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...

Upvotes: 1

Views: 523

Answers (3)

user936414
user936414

Reputation: 7634

Try LongClickListener for the button. It may suite your requirement.

 button.setOnLongClickListener(new OnLongClickListener(
            ) {

        @Override
        public boolean onLongClick(View arg0) {
            // TODO Auto-generated method stub
            //do the necessary here
            return true;
        }
    });

Upvotes: 2

Paresh Mayani
Paresh Mayani

Reputation: 128448

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.

Upvotes: 1

Suman
Suman

Reputation: 4251

Try using context menu , this will be specific to the message and is easy as well. Its similar to options menu.

Upvotes: 1

Related Questions