have now tried using this code but keep getting a null value when I hit enter? Can anyone suggest a solution to avoid this?
editext.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey (View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode==KeyEvent.KEYCODE_ENTER) {
if ("test1".equalsIgnoreCase(editext.getText().toString())) {
but4.performClick();
}
}
else if ("test2".equalsIgnoreCase(editext.getText().toString())) {
but5.performClick();
}
if ("test5".equalsIgnoreCase(editext.getText().toString())) {
but6.performClick();
}
if ("test7".equalsIgnoreCase(editext.getText().toString())) {
but7.performClick();
}
if (editext.getText().toString() != null){
testwrong.seText("wrong");
}
return true;
}
});
According to the documentation, the
keyCodevalue corresponds to the hardware key pressed. This probably does not refer to the soft keyboard.Try to get the value of the keyboard key pressed from the
KeyEvent.