2013-11-24 57 views

回答

3

有你看了developer documentation on handling key events?你可以嘗試的onkeydown或的onkeyup只接收一個事件,並打印出的keyCode看到的是越來越收到什麼:

@Override 
public boolean onKeyUp(int keyCode, KeyEvent event) { 
    Log.i("your tag", "Keycode: " + keyCode); 
    switch (keyCode) { 
    case KeyEvent.KEYCODE_DPAD_LEFT: 
     leftKeyClick(); 
     return true; 
    case KeyEvent.KEYCODE_DPAD_RIGHT: 
     rightKeyClick(); 
     return true; 
    case KeyEvent.KEYCODE_DPAD_UP: 
     upKeyClick(); 
     return true; 
    case KeyEvent.KEYCODE_DPAD_DOWN: 
     downKeyClick(); 
     return true; 
    default: 
     return super.onKeyUp(keyCode, event); 
    } 
} 

KeyEvent Object reference gives more details.如果您還沒有檢測箭頭鍵然後你可能需要重寫你的視圖的onKeyDown或onKeyUp方法,this similar question might be useful.

相關問題