Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable DPAD keys in android

I am trying to catch events generated by the arrow keys (UP, DOWN, RIGHT and LEFT) and disable them. Below code snippet is from one of the activity class.

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if(event.getAction() == KeyEvent.KEYCODE_DPAD_DOWN) return true;
    else return true;
}

However, with those code in place, key navigation is working. I tried adding key listener to activity which doesn't work either.

The target device is Samsung GT-I5500 with Android 2.2 version on.

Am I missing anything?

like image 247
Renjith Avatar asked Mar 24 '23 07:03

Renjith


1 Answers

Override onKeyDown also and return true and not false. Somnething like this:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
        case KeyEvent.KEYCODE_DPAD_RIGHT:
        case KeyEvent.KEYCODE_DPAD_UP:
        case KeyEvent.KEYCODE_DPAD_DOWN:
            return true; 
    }
    return false;
}
like image 131
alexandr.opara Avatar answered Apr 05 '23 22:04

alexandr.opara