5

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

BerHug
  • 225
  • 2
  • 17

1 Answers1

4

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); 
}
louis amoros
  • 2,418
  • 3
  • 19
  • 40
Nouman Ch
  • 4,023
  • 4
  • 29
  • 42