Whenever a user presses the search button and the SearchView component is shown, it goes back to the button MenuItem once a query is submitted.

However, when a user press the Back key, only the keyboard is hidden but the SearchView component is still visible. If you press the Back key again, one would expect the SearchView to be iconified but the app exits instead.

The workaround for this is to add an OnFocusChangeListener to the SearchView component. Whenever the keyboard gets shown and hidden, the onFocusChange() method gets called.

Here is the code:

This is how to simulate a back key press event in Android programmatically. Do note that this is called twice to dispatch a key event for both UP and down actions.

If only one of these two is executed, it will not work so make sure both of these are executed.

You wonder in your Java Swing application why after pressing the TAB key and the next button has focus, nothing happens when you press the ENTER key. Then you find out only the SPACE key works. The culprit here is the look and feel.

The ENTER key works only in the Windows look and feel. Other look and feel themes have the SPACE character as its ENTER representation. If you want to mimic the ENTER key instead of the SPACE key even though your look and feel theme is not Windows, here is how you do it.

Related Posts Plugin for WordPress, Blogger...