android: Softkeyboard perform action when Done key is pressed

Khawar Raza picture Khawar Raza · Sep 28, 2011 · Viewed 37.3k times · Source

I have an EditText. I want that after typing some text, when user presses the Done key of the softkeyboard, it should directly perform some search operation which I have also implemented in a button click event.

Answer

Adil Soomro picture Adil Soomro · Sep 28, 2011

Try this

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