本文介绍了这事件被称为当用户点击右键菜单中禁用的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有按钮,用于显示快捷菜单。在菜单中有几个项目。(其中一些被禁止 - 的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;
}
}
这篇关于这事件被称为当用户点击右键菜单中禁用的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!