How to dismiss a ContextMenu without the Back button?

2.2k views Asked by At

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?

2

There are 2 answers

1
Buda Gavril On BEST ANSWER

dispatch a key event (back)and you're done.

myView.getRootView().dispatchKeyEvent(new KeyEvent (KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
0
Travis On

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?