Skizit Skizit - 10 months ago 49
Java Question

Listener for Done button on EditText?

If I have an EditText and I want to listen for if the user presses the "done" button on the keypad.. how would I do this?


Code is

final EditText edittext = (EditText) findViewById(;
edittext.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                Toast.makeText(HelloFormStuff.this, edittext.getText(), Toast.LENGTH_SHORT).show();
                return true;
            return false;

In that 'edittext' is id of textfield

Check out this link Simply set setOnKeyListener to your editText