再次求java 键盘事件问题 KeyListener

2024-12-22 23:59:54
推荐回答(3个)
回答1:

一个事件源,多个监听器。这么做比较容易解决。你给事件源添加两次监听器,两个不同的监听器。

回答2:

public boolean onKey(View v, int keyCode, KeyEvent event) {

if(event.getAction()==KeyEvent.ACTION_DOWN){
int shu ;
NoteDebug((String) Text_hide7.getText());
switch (keyCode) {
case KeyEvent.KEYCODE_0:
numberOnClick("0");
break;
case KeyEvent.KEYCODE_1:
numberOnClick("1");
break;
case KeyEvent.KEYCODE_2:
numberOnClick("2");
break;
case KeyEvent.KEYCODE_3:
numberOnClick("3");
break;
case KeyEvent.KEYCODE_4:
numberOnClick("4");
break;
case KeyEvent.KEYCODE_5:
numberOnClick("5");
break;
case KeyEvent.KEYCODE_6:
numberOnClick("6");
break;
case KeyEvent.KEYCODE_7:
numberOnClick("7");
break;
case KeyEvent.KEYCODE_8:
numberOnClick("8");
break;
case KeyEvent.KEYCODE_9:
numberOnClick("9");
break;
case KeyEvent.KEYCODE_PERIOD:
edittext.setText(edittext.getText() + ".");
edittext.setSelection(edittext.length());
shu = Integer.parseInt(String.valueOf( Text_hide7.getText()));
Text_hide7.setText(String.valueOf(shu +1));
break;
default:
shu = Integer.parseInt(String.valueOf( Text_hide7.getText()));
Text_hide7.setText(String.valueOf(shu +1));
break;
}
if(keyCode==event.KEYCODE_TAB){

}else if(keyCode==27){

}
}
return true;
}

回答3:

利用线程就能实现你所说的哈