1

I have an EditText. On a setOnKeyListener of an EditText, I want to perform the following action.

  1. On click of the Done button of the keyboard, I want to display something in my TextView.

  2. On click of other buttons, not the done button, I want to make the TextView blank.

So for that, I write the code but it works for the click of a done button but not for other buttons. so can anyone help me to solve this out?

My Code

EditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { m_passwrdErrorText.setText(m_res.getString(R.string.passwrd_error_text)); } else { m_passwrdErrorText.setText(""); } return false; } }); 

1 Answer 1

3

can try

editText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { // do your stuff here } return false; } }); 
Sign up to request clarification or add additional context in comments.

2 Comments

Ok on done its work..but if i click other buttons except done then i want to do something...means if i press numbers, or letters in keyboard i want to don some action..how that can be done

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.