Skip to content Skip to sidebar Skip to footer

Dispatchkeyevent() Invoking Twice

I debugged the following snippet and come to know the method dispatchKeyEvent() is invoked twice. please suggest the solution @Override public boolean dispatchKeyEvent(KeyEven

Solution 1:

dispatchKeyEvent fire twice: the first time for key down, and the second time for key up, so you have to filter:

 if (event.getAction()!=KeyEvent.ACTION_DOWN)
                return true;

            switch (keyCode) {
            case KeyEvent.KEYCODE_1 : 
                MakeToast(1);
                break;
            case KeyEvent.KEYCODE_2 : 
                MakeToast(2);
                break;
            case KeyEvent.KEYCODE_3 : 
                MakeToast(3);
                break;

            }

Post a Comment for "Dispatchkeyevent() Invoking Twice"