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
Post a Comment