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 -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -