Reputation: 3617
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?
Upvotes: 4
Views: 2838
Reputation: 454
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;
}
Upvotes: 7
Reputation: 3636
In the documentation, it is stated that you should return:
Your method is returning false, so you are passing the event to the default key handler
Upvotes: 0