Android Development: How To Use onKeyUp?

前端 未结 6 1453
执念已碎
执念已碎 2020-12-17 10:22

I\'m new to Android development and I can\'t seem to find a good guide on how to use an onKeyUp listener.

In my app, I have a big EditText,

6条回答
  •  遥遥无期
    2020-12-17 10:46

    You may consider using the following code:

     @Override 
     public boolean onKeyUp(int keyCode, KeyEvent event) {
        switch (keyCode) {
            ...
            case KeyEvent.KEYCODE_J:
                if (event.isShiftPressed()) {
                    fireLaser();
                } else {
                    fireMachineGun();
                }
                return true;
            case KeyEvent.KEYCODE_K:
                if (event.isShiftPressed()) {
                    fireSeekingMissle();
                } else {
                    fireMissile();
                }
                return true;
            default:
                return super.onKeyUp(keyCode, event);
        } }
    

    Here In the end we have called the super.onkeyUp method. Which handles the event when the user do not presses the valid key.

    For more details you may consider following link.

提交回复
热议问题