2

I have inherited EditText class an made my custom class, MyEditText.

and want to detect key pressed(say 'a', 'b', 'c'... '0', '1', '2'... etc.) event in Android. How?

It seems overridden method onKeyDown(int keyCode, KeyEvent event) is called when 'back', '\', '/', 'DEL', '@' keys are pressed, but not for any numeric or alphabets.

Samir
  • 3,923
  • 9
  • 36
  • 43

1 Answers1

2

Maybe what you need is not a keypress event, but a text change event. Then you can use addTextChangedListener method.

ognian
  • 11,451
  • 4
  • 35
  • 33
  • Hello ognian, can I suppress this change event from inside afterTextChanged or beforeTextChanged or onTextChanged? Say the pressing of 'a' (or other char) will not go to the edittext? – Samir Jul 14 '10 at 11:37
  • Use InputFilter instead: http://developer.android.com/reference/android/widget/TextView.html#setFilters%28android.text.InputFilter[]%29 – ognian Jul 15 '10 at 05:12
  • Ya, with InputFilter I can now control the text. – Samir Jul 16 '10 at 06:50