当用户单击上下文菜单中的禁用项目时,会调用哪个事件?

发布于 2024-09-29 04:43:51 字数 165 浏览 1 评论 0原文

我有一个按钮,它显示上下文菜单。菜单中有几个项目(其中一些被禁用 - setEnabled(false))。

当用户单击禁用的项目时,会调用哪个事件?它不是 onContextItemSelected 也不是 onContextMenuClosed。但点击后菜单关闭。

感谢您的帮助。

I have button, which displays a Context menu. In the menu are few items (some of them are disabled - setEnabled(false)).

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.

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

歌入人心 2024-10-06 04:43:51

经过与老师协商后,我已经解决了这个问题。您可以检查窗口的焦点,然后确定上下文菜单是否关闭。

所以你必须:

  1. 使用下面的代码。
  2. 创建上下文菜单时调用 onPrepareContextMenu() 方法。

代码:

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;
    }

}

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.

So you have to:

  1. Use the code below.
  2. Call onPrepareContextMenu() method when you create the context menu.

The 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;
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文