由网友(等太阳升起)分享简介:我有按钮,用于显示快捷菜单。在菜单中有几个项目。(其中一些被禁止 - 的setEnabled(假))I have button, which displays a Context menu. In the menu are few items (some of them are disabled - setEnabl...
我有按钮,用于显示快捷菜单。在菜单中有几个项目。(其中一些被禁止 - 的setEnabled(假))
I have button, which displays a Context menu. In the menu are few items (some of them are disabled - setEnabled(false)).
这事件被调用时的禁用的项目,用户点击?这不是onContextItemSelected也不onContextMenuClosed。但菜单后,点击关闭。
Which event is called when a user click on the disabled item? It's not onContextItemSelected nor onContextMenuClosed. But the menu is closed after the click.
感谢您的帮助。
推荐答案
我的老师协商后,我已经解决了这个问题。你可以检查你的窗口的焦点,然后再决定是否在上下文菜单已关闭或没有。
After consultation with my teacher, I've solved the problem. You can check the focus of your window, and then decide if the context menu was closed or not.
所以,你必须:
使用下面的code。 呼叫在prepareContextMenu()方法,当你创建上下文菜单。 Use the code below. Call onPrepareContextMenu() method when you create the context menu.在code:
public class MyActivity extends android.app.Activity {
private boolean contextMenuDisplayed = false;
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(hasFocus && this.contextMenuDisplayed) {
this.contextMenuDisplayed = false;
this.onContextMenuClosed(null);
}
}
public void onPrepareContextMenu() {
this.contextMenuDisplayed = true;
}
}
相关推荐
最新文章