I\'m new to Android development and I can\'t seem to find a good guide on how to use an onKeyUp listener.
In my app, I have a big EditText,
If you use device with no touch but with hard keypad buttons (keyboard) use this code to control the events of moving left right up down and ok. use onkeyDown and not onKeyUp because the onKeyup will return the next button events:
Button myButton = (Button) findViewById(R.id.my_btn);
myButton .setKeyListener(new KeyListener() {
@Override
public int getInputType() {
return 0;
}
@Override
public boolean onKeyDown(View view, Editable editable, int keyCode, KeyEvent keyEvent) {
Log.d("myTag", "onKeyDown code: " +keyCode);
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_RIGHT:
// USER_MOVE_RIGHT();
return true;
case KeyEvent.KEYCODE_DPAD_LEFT:
//USER_MOVE_LEFT());
return true;
case KeyEvent.KEYCODE_DPAD_DOWN:
//USER_MOVE_DOWN());
return true;
case KeyEvent.KEYCODE_DPAD_UP:
//USER_MOVE_UP();
return true;
case KeyEvent.KEYCODE_DPAD_CENTER:
//USER_Press_OK()
return true;
}
return false;
}