Android (Milestone/Droid): View.OnKeyListener not working correctly?

I am using a simple EditText and register an View.OnKeyListener. Some GUI changes should happen (fading in/out of views) when certain conditions for the EditView text apply. In the emulator, this works as expected. On the Motorola Droid/Milestone, the listener does not work, only

  1. after pressing DEL, the listener is called the first time and always afterwards
  2. when activating the number input, the listener works correctly

Note: I deactivated the suggestions with TYPE_TEXT_FLAG_NO_SUGGESTIONS and used the IME action IME_ACTION_GO to have a workaround for this (otherwise the user could not "start" a request).

Asked by: Sarah917 | Posted: 20-01-2022

Answer 1

Found a better and working way to implement this: use EditText.addTextChangedListener with a TextWatcher class (and implement TextWatcher.onTextChanged(CharSequence s, int start, int before, int count)), works perfectly also on the Milestone/Droid.

Answered by: Julia317 | Posted: 21-02-2022

Answer 2

TextWatcher cannot fully replace onKeyListener. For example, if your textbox is empty, how would you detect that user pressed DEL key? Or, what if you don't have textbox at all and you want to detect key events?

Answered by: Dainton397 | Posted: 21-02-2022

Similar questions

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android