William Melani
William Melani

Reputation: 4268

Preventing a View from showing two Context Menus

In my Android application I have a Button which opens up a context menu when clicked. The issue is that if a user clicks quickly, they can open multiple instances of the menu.

b.setOnClickListener( new OnClickListener() {
@Override
public void onClick( View view ) {
    // popup options            
    view.showContextMenu();
}
} );

How can I prevent the user from opening up more than one copy? I am looking for a 'boolean' like checking the Visible status, but can't seem to find anything. My hope was that there was a function somehow that would result in code similar to:

if (context menu is not open)
     open context menu
else 
     don't do anything

Upvotes: 1

Views: 388

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007494

I really don't like this UI pattern. It's this sort of thing that cause iOS developers (and users) to think that Android developers lack discipline. Context menus are for long-presses, period. Use something else, like an AlertDialog or PopupMenu, elsewhere.

That being said, set a boolean flag when you show the context menu, checking it first to prevent duplicate menus. Clear the flag in onContextMenuClosed().

Upvotes: 1

Related Questions