I am working with android 2.2.
How to know which character is get deleted on backspace when editing text in custom auto complete in android.
public boolean onKeyUp(int keyCode,KeyEvent msg){
if(keyCode == KeyEvent.KEYCODE_DEL)
{
// how to find here which character is get deleted
}
return false;
}
String prevText = "";
public boolean onKeyUp(int keyCode,KeyEvent msg){
if(keyCode == KeyEvent.KEYCODE_DEL)
{
int pos = myEditText.getSelectionStart();
char c = prevText.charAt(pos);
// c is deleted
}
prevText = myEditText.getText.toString();
return false;
}
You can use add a TextWatcher
to AutoCompleteTextView with addTextChangeListener(TextWatcher)
.
You don't need to listen to onKeyUp()
the various TextWatcher methods inform you if the user is adding or removing text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With