views:

73

answers:

1

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.

+1  A: 

Hi,

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

ognian
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
Use InputFilter instead: http://developer.android.com/reference/android/widget/TextView.html#setFilters%28android.text.InputFilter[]%29
ognian
Ya, with InputFilter I can now control the text.
Samir