Android soft keyboard letters not being detected

  • Replies:1
Alex Walker
  • Forum posts: 1

Nov 25, 2013, 12:31:32 PM via Website

I have an "edittext" in my app, and I want to do things when certain characters are pressed on the soft keyboard. I have tried every which way and how stackOverflow suggests, however characters i.e a/A, b/B etc dont get detected. Enter and Del do however. After reading loads, Apparently I have to override the edittext class, according to an example on here, so I have done that. I am overriding the method here:
1@Override
2 public boolean sendKeyEvent(KeyEvent event) {
3 if (event.getAction() == KeyEvent.ACTION_DOWN
4 && event.getKeyCode() == KeyEvent.KEYCODE_A) {
5 ZanyEditText.this.setRandomBackgroundColor();
6
7 return false;
8 }
9 return super.sendKeyEvent(event);
10 }
I also have tried overriding the standard edittext onKeyListener:
1txtSMS.setOnKeyListener(new View.OnKeyListener() {
2 @Override
3 public boolean onKey(View v, int keyCode, KeyEvent event) {
4 // You can identify which key pressed buy checking keyCode value
5 // with KeyEvent.KEYCODE_
6 if (keyCode == KeyEvent.KEYCODE_DEL) {
7 // this is for backspace
8 Toast.makeText(getApplicationContext(), "Del was pressed", Toast.LENGTH_SHORT).show();
9 }
10 if (keyCode == KeyEvent.KEYCODE_A) {
11 // this is for backspace
12 Toast.makeText(getApplicationContext(), "A was pressed", Toast.LENGTH_SHORT).show();
13 }
14 return false;
15 }
However in both cases on the Del is ever detected. how come I cant detect characters of the alphabet? They appear in the text box...
Really I would like it not to need a textbox at all, and just show the keyboard, but I dont think thats possible?
Thanks

Reply
Deactivated Account
  • Forum posts: 18

Dec 18, 2013, 3:59:10 PM via Website

those keylisteners works only with hard keys for jelly bean and up.
you should create a custom class for soft key listener, or try this EditText.addTextChangedListener(new TextWatcher(){})

Reply