我想知道按下了哪个键。我有一个 EditText 并为它添加了一个 KeyListener。但它似乎没有工作。我有一个文本视图,我想设置在文本视图上按下的 setText。
edittext = (EditText)findViewById(bla);
textview = (TextView)findViewById(bla);
edittext.setKeyListener(new Keylistener(){
@Override
public void clearMetaKeyState(View view,
Editable content, int states) {
// TODO Auto-generated method stub
}
@Override
public int getInputType() {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean onKeyDown(View view, Editable text,
int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_DEL){
textview.setText("delete");
}
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onKeyOther(View view, Editable text,
KeyEvent event) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onKeyUp(View view, Editable text,
int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_DEL){
textview.setText("delete");
}
return false;
}
});
这应该非常简单,但我无法让它工作:)