Android detect Done key press for OnScreen Keyboard

Android

Android Problem Overview


Is it possible to detect when the Done key of onScreen keyboard was pressed ?

Android Solutions


Solution 1 - Android

Yes, it is possible:

editText = (EditText) findViewById(R.id.edit_text);

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;
    }
});

Note that you will have to import the following libraries:

import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;

Solution 2 - Android

> An Editor Info is most useful class when you have to deal with any > type of user input in your Android application. For e.g. in > login/registration/search operations we can use it for more accurate > keyboard input. An editor info class describes several attributes for > text editing object that an input method will be directly > communicating with edit text contents.

You can try with IME_ACTION_DONE .

This action performs a Done operation for nothing to input and the IME will be closed.

Using setOnEditorActionListener

EditTextObj.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        boolean handled = false;
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            /* Write your logic here that will be executed when user taps next button */
            handled = true;
        }
        return handled;
    }
});

Solution 3 - Android

Using Butterknife you can do this

@OnEditorAction(R.id.signInPasswordText)
boolean onEditorAction(TextView v, int actionId, KeyEvent event){
    if (actionId == EditorInfo.IME_ACTION_DONE || event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
        /* Write your logic here that will be executed when user taps next button */
    }
    return false;
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpankajagarwalView Question on Stackoverflow
Solution 1 - AndroidSzabolcs BereczView Answer on Stackoverflow
Solution 2 - AndroidIntelliJ AmiyaView Answer on Stackoverflow
Solution 3 - AndroidZayin KrigeView Answer on Stackoverflow