0

Looking at the Android documentation here:

https://developer.android.com/training/keyboard-input/style.html,

specifically:

EditText editText = (EditText) findViewById(R.id.search);
editText.setOnEditorActionListener(new OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        boolean handled = false;
        if (actionId == EditorInfo.IME_ACTION_SEND) {
            sendMessage();
            handled = true;
        }
        return handled;
    }
});

This does not close the keyboard after clicking the send button. It also does not close the keyboard if handled is set to false.

What is the appropriate way to hide the keyboard in this case?

Looking at :-

how to hide keyboard after typing in EditText in android?, there seems to be a multitude of ways. Is this really the way to go in Android?

Abhinav Gupta
  • 2,225
  • 1
  • 14
  • 30
HelloWorld
  • 3,381
  • 5
  • 32
  • 58
  • Yes I think you need to hide it manually. If I remember correctly, the keyboard only hide automatically on IME_ACTION_DONE as describe in the answer you've linked. IME_ACTION is a big mess, the button is supposed to display the action (e.g. a 'done' button is displayed on IME_ACTION_DONE), but in reality it depends on the keyboard implementation. Welcome to Android world ;) – Eselfar Mar 13 '18 at 13:06
  • @Eselfar thanks! the example has some logic for 'handled', but I can't seem to divulge the meaning behind it, as neither true nor false does not close the keyboard nor clear the edittext. does android actually use the boolean value returned, for anything at all? – HelloWorld Mar 13 '18 at 13:16
  • This is a mess, returning true should close the keyboard it doesn't. Returning false shouldn't. So you have to manually close the keyboard if the condition of IME action is met. – Dharmendra Pratap Singh May 21 '19 at 14:40

0 Answers0