BerHug
BerHug

Reputation: 225

Handle keyboard navigation arrows

On a Samsung Tablet, we have the following keyboard: enter image description here

When a clic occurred on the right bottom arrows, in the view pager, fragment is changed. I want to intercept this event or remove the arrows from the keyboard. Is it possible ?

I tried to intercept keyevent with onKeyUp and onKeyDown methods, but it's not working:

if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT || event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) {
  return true;
}

My problem is the same as here

Upvotes: 5

Views: 506

Answers (1)

Nouman Ch
Nouman Ch

Reputation: 4121

Try to use dispatchKeyEvent(KeyEvent event):

 @Override 
 public boolean dispatchKeyEvent(KeyEvent event) {

     Log.i("key pressed ", String.valueOf(event.getKeyCode()));
     if(event.getKeyCode() == KeyEvent.KEY_A /*select required keycode*/ ){
        // perform task
     }
     return super.dispatchKeyEvent(event); 
}

Upvotes: 4

Related Questions