I\'m struggling with the done button on the soft keyboard. I can\'t get the soft keyboard Done key press to hide the keyboard. From another button, it works perfectly with
SoftKeyboard can be hide by following way
In Java class we can write following code to hide keyboard when user press done or enter
etBid.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH ||
actionId == EditorInfo.IME_ACTION_DONE ||
event != null &&
event.getAction() == KeyEvent.ACTION_DOWN &&
event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
{
if (event == null || !event.isShiftPressed())
{
// the user is done typing.
InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
return true; // consume.
}
}
return false; // pass on to other listeners.
}