android - How to filter the input of EditText? -


i want filter input of edittext, digits , letters allowed, first use textwatcher deal last input character, when move cursor or past content edittext, method failed, want know there way filter illegal input , give user feedback.

add inputfilter edittext & provide toast user . this code snippet you.

 inputfilter filter = new inputfilter() {                 public charsequence filter(charsequence source, int start, int end,                         spanned dest, int dstart, int dend) {                     (int = start; < end; i++) {                         if (!character.isletterordigit(source.charat(i))) { // accept letter & digits ; otherwise return                             toast.maketext(context,"invalid input",toast.length_short).show();                             return "";                         }                     }                     return null;                 }              };          edittext.setfilters(new inputfilter[] { filter }); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -