Android Keyboard Events

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.