android - How to detect KEYCODE_DEL on soft keyboard? -


mmessagecomposeusernames multiautocompletetextview , want delete space (if last char of multiautocompletetextview) or delete single word (to last " ", if not).

code:

mmessagecomposeusernames.setonkeylistener(new view.onkeylistener() {         @override         public boolean onkey(view v, int keycode, keyevent event) {             //you can identify key pressed buy checking keycode value keyevent.keycode_             if(keycode == keyevent.keycode_del){                 string string = mmessagecomposeusernames.gettext().tostring();                 if (!string.substring(string.length() - 1).equals(" ")) {                     if (string.contains(" ")) {                         string = string.substring(0, string.lastindexof(" "));                     } else {                         string = "";                     }                 }                 log.i("string", string);                 mmessagecomposeusernames.settext(string);             }             return false;         }     }); 

the problem nothing in logs, think onkey isn't executed... how can want when keycode_del 'pressed' on soft keyboard? :)

you can below code implement idea:

 string yourstring1 = yourstring.trim();  if(!yourstring.equals(yourstring1)){      yourstring = yourstring.replace(yourstring.substring(str.length()-1), "");  } 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -