开发者

How can I detect any key pressed (numeric, alphabet) event in Android for EditText

开发者 https://www.devze.com 2023-01-06 21:33 出处:网络
I have inherited EditText class an made my 开发者_JS百科custom class, MyEditText. and want to detect key pressed(say \'a\', \'b\', \'c\'... \'0\', \'1\', \'2\'... etc.) event in Android. How?

I have inherited EditText class an made my 开发者_JS百科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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消