Keyboard hide event with BACK key

Mohammad Ersan picture Mohammad Ersan · Oct 3, 2011 · Viewed 13.9k times · Source

I've noticed in the Android Market Application, when you click over the search button, it shows the keyboard, but when you click the back button, the search EditText becomes invisible and the keyboard is hidden. The problem is that I can't hide the EditText after the keyboard is hidden after pressing the back key because I can't find a listener for hiding the keyboard event. I found this sample How to capture the "virtual keyboard show/hide" event in Android? but it doesn't work on the soft keyboard.

Answer

hackbod picture hackbod · Oct 9, 2011

You need to implement this to capture the BACK button before it is dispatched to the IME:

http://developer.android.com/reference/android/view/View.html#onKeyPreIme(int, android.view.KeyEvent)