How to dismiss a ContextMenu without the Back button?
-
13-12-2019 - |
Question
The application has a contextmenu opened and I want to close/dismiss it without using the back button. Is it possible to receive a click event somewhere so I can call close?
closeContextMenu ()
Or can I call
setCancelOnTouchOutside()
somewhere like I can on a Dialog? Alternative for me is to refactor all my context menu's to PopupWindows which can also do
setOutsideTouchable()
Anyone a good hint/idea?
Solution
dispatch a key event (back)and you're done.
myView.getRootView().dispatchKeyEvent(new KeyEvent (KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
OTHER TIPS
It sounds like you're describing a cancel listener type of behavior like you'd use in a dialog, but why not just use the back button?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow