Search code examples
androidandroid-edittextimeoptions

How to trigger a event when user press done button in keyboard


I want to trigger an event when the user clicks done button in android keyboard

For Example: In login activity when I enter the password and press done button at right bottom corner of keyboard it close the keyboard and then I press the login button. Instead of that when the user press done button in keyboard the authentication should happen.


Solution

  • editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                // do your stuff here
            }
            return false;
        }
    });