Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listener for Done button on EditText? [duplicate]

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?

like image 813
Skizit Avatar asked Apr 15 '11 13:04

Skizit


2 Answers

Dinash answer is nice, but it is not working on all devices. Below code works fine for all devices

edittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {     @Override     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {         if (actionId == EditorInfo.IME_ACTION_DONE) {             Toast.makeText(HelloFormStuff.this, edittext.getText(), Toast.LENGTH_SHORT).show();             return true;         }         return false;     } }); 
like image 191
Asad Rao Avatar answered Sep 19 '22 07:09

Asad Rao


Code is

final EditText edittext = (EditText) findViewById(R.id.edittext); 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

like image 20
Dinash Avatar answered Sep 20 '22 07:09

Dinash