Skizit Skizit - 2 years ago 89
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download