android - onTextChanged prevet space / new line -


i trying , not work: trying prevent space key writing edittext , not prevent that, i`m trying code:

@override public void ontextchanged(charsequence s, int start, int before, int count) {     if((addresstextbox.gettext().tostring().contains(" "))) {         return;     } } 

how can prevent new line (ascii char number 10) ?

for new line add android:singleline="true" "edittext" in xml file

for blank space use (as said @aksiddique in answer)

@override public void aftertextchanged(editable s) {     string result = s.tostring().replaceall(" ", "");     if (!s.tostring().equals(result)) {          ed.settext(result);          ed.setselection(result.length());          // alert user     } } 

give try , luck!


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -