开发者

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 wa开发者_运维问答s a function somehow that would result in code similar to:

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜