I'm working on a remote control app and need to detect when a user pressed the <x
delete button on an empty text field to send this character over and delete something from a remote machine.
How can I detect that the user pressed <x
Delete button on Android keyboard?
I tried to ad on key listener, but that did not seem to work.
final EditText edittext = (EditText) findViewById(R.id.editText);
edittext.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
Log.i("KEYCODE", "" + keyCode);
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
return false;
} else if (edittext.length() == 0) {
if(keyCode == KeyEvent.KEYCODE_DEL) {
//perform erase when the text field is empty
}
}
return false;
}
});