监听上下左右键

 public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_CENTER:
            display("中键报道,被按下");
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            display("下键报道,被按下");
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            display("左键报道,被按下");
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            display("右键报道,被按下");
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            display("上键报道,被按下");
            break;
        }
        return super.onKeyDown(keyCode, event);
    }

你可能感兴趣的:(监听上下左右键)