开发者

Which event is called when a user click on the disabled item in context menu?

开发者 https://www.devze.com 2023-01-23 00:39 出处:网络
I have button, which displays a Context menu. In the menu are few items (some of them are disabled - setEnabled(false)).

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开发者_如何学Go? It's not onContextItemSelected nor onContextMenuClosed. But the menu is closed after the click.

Thanks for your help.


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

}
0

精彩评论

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