以下是我用来获取键事件的方法,这些方法在模拟器上运行正常,但似乎无法在设备上运行。
以下是我用来获取键事件的方法,这些方法在模拟器上运行正常,但似乎无法在设备上运行。
edTest.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(keyCode == KeyEvent.KEYCODE_SPACE)
{
Log.e("keylistner", "keylistner");
}
return false;
}
});
edTest.setKeyListener(new KeyListener() {
@Override
public boolean onKeyUp(View view, Editable text, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(keyCode == KeyEvent.KEYCODE_SPACE)
{
Log.e("keylistner", "keylistner");
}
return false;
}
@Override
public boolean onKeyOther(View view, Editable text, KeyEvent event) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onKeyDown(View view, Editable text, int keyCode,
KeyEvent event) {
// TODO Auto-generated method stub
if(keyCode == KeyEvent.KEYCODE_SPACE)
{
Log.e("keylistner", "keylistner");
}
return false;
}
@Override
public int getInputType() {
// TODO Auto-generated method stub
return 1;
}
@Override
public void clearMetaKeyState(View view, Editable content, int states) {
// TODO Auto-generated method stub
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(keyCode == KeyEvent.KEYCODE_SPACE)
{
Log.e("onkeydown", "onkeydown");
}
return super.onKeyDown(keyCode, event);
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
// TODO Auto-generated method stub
if(event.getKeyCode() ==KeyEvent.KEYCODE_SPACE)
{
Log.e("dispatch", "dispatch");
}
return super.dispatchKeyEvent(event);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(event.getKeyCode() ==KeyEvent.KEYCODE_SPACE)
{
Log.e("onkeyup", "onkeyup");
}
return super.onKeyUp(keyCode, event);
}