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;
    }
});
iknow
  • 8,358
  • 12
  • 41
  • 68
AndroidDev
  • 4,521
  • 24
  • 78
  • 126

1 Answers1

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;
    }
});
Dheeresh Singh
  • 15,643
  • 3
  • 38
  • 36
  • http://stackoverflow.com/questions/2004344/android-edittext-imeoptions-done-track-finish-typing – Dheeresh Singh May 30 '12 at 09:28
  • 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 – AndroidDev May 30 '12 at 09:32