Did you rewrite the Dispatchkeyevent event in the activity, and will not execute the onkeydown event regardless of whether the final return is true or false?
Some of the information found is not explained in this way:
When the keyboard is pressed
First Trigger Dispatchkeyevent
And then trigger onuserinteraction.
Again onkeydown
If you press and release immediately, it is two steps
Follow the trigger dispatchkeyevent
And then trigger onuserinteraction.
Again onkeyup
Dispatchkeyevent is doing the key handling and distributing work, if you want to onkeydown can also receive should be implemented like this
public boolean dispatchkeyevent (KeyEvent event) {
Return Super.dispatchkeyevent (event);
}
The code tests are as follows:
The dispatchkeyevent (KeyEvent event) Press-and-hold action is performed when a key operation is completed, regardless of whether the return is true or FALSE, OnKeyDown (int keycode, KeyEvent event) and onkeyup (int keycode, keyevent event) are no longer keystroke-handling :
1th Case and log information:
Public void debug (STRING STR) {  LOG.D (TAG, STR); } @Override public boolean onkeydown ( Int keycode, keyevent event) { TODO Auto-generated method stub debug (" onKeyDown " + keyCode ); return super.onkeydown (keycode, event); } @Override public boolean onkeylongpress (int keycode, keyevent event) { // tOdo auto-generated method stub debug (" onKeyLongPress " + keyCode ); return super.onkeylongpress (keycode, event); } @Override public boolean Dispatchkeyevent (keyevent event) { // TODO Auto-generated method stub debug (" dispatchKeyEvent 1 key = " + event.getkeycode () + " event = " + event.getaction ()); if (Event.getaction () ==keyevent.action_down) { &nbSp; debug (" dispatchkeyevent 2 action_down" + event.getkeycode () ); return Super.dispatchkeyevent (Event); } if (Event.getaction () ==keyevent.action_up) { debug (" dispatchKeyEvent 3 Action_up " + event.getkeycode () ); return super.dispatchkeyevent (Event); } return Super.dispatchkeyevent (Event); } @Override pubLic boolean onkeyup (int keycode, keyevent event) { // TODO Auto-generated method stub debug (" onKeyUp " + keycode); return super.onkeyup (keycode, event); }
Log information:
D/testmainactivity (853): dispatchkeyevent 1 key = all event = 0
D/testmainactivity (853): Dispatchkeyevent 2 action_down23
D/testmainactivity (853): OnKeyDown 23
D/testmainactivity (853): dispatchkeyevent 1 key = all event = 1
D/testmainactivity (853): Dispatchkeyevent 3 action_up23
D/testmainactivity (853): OnKeyUp 23
Android Keyboard Events