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

后端 未结 1 1671
醉梦人生
醉梦人生 2021-01-21 15:59

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 d

相关标签:
1条回答
  • 2021-01-21 16:10

    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 讨论(0)
提交回复
热议问题