I have an Activity
with an EditText
, a button and a ListView
. The purpose is to type a search screen in the EditText
, press the button and have the search results populate this list.
This is all working perfectly, but the virtual keyboard is behaving strange.
If I click the EditText
, I get the virtual keyboard. If I click the "Done" button on the virtual keyboard, it goes away. However, if I click my search button before clicking "Done" on the virtual keyboard, the virtual keyboard stays and I can't get rid of it. Clicking the "Done" button does not close the keyboard. It changes the "Done" button from "Done" to an arrow and remains visible.
Thanks for your help
Crash Null Point Exception Fix: I had a case where the keyboard might not open when the user clicks the button. You have to write an if statement to check that getCurrentFocus() isn't a null:
Since you have only one edit text then just call action done for that edit text inside your button click and the rest is handled by the system. If you had more than one edittext then this would not be so efficent because you have to get the focused edittext first. But in your case it will work perfectly
If you set
android:singleLine="true"
, automatically the button hides the keyboard¡I put this right after the
onClick(View v)
event.You need to import
android.view.inputmethod.InputMethodManager
;The keyboard hides when you click the button.
Use Below Code