android edittext inputfilter should accept space,character & number
street = (EditText) findViewById(R.id.street);
InputFilter filter = new InputFilter() {
public CharSequence filter(CharSequence source, int start, in开发者_JAVA技巧t end,Spanned dest, int dstart, int dend) {
for (int i = start; i < end; i++) {
if (!Character.isLetterOrDigit(source.charAt(i)) || !Character.isSpaceChar(source.charAt(i))) {
return "";
}
}
return null;
}
};
street.setFilters(new InputFilter[] { filter });
my edittext is able to filter character & number on the virtual keyboard but not taking the space character.. plz help
instead of '||' i replaced with '&&' and got the answer....
!Character.isLetterOrDigit(source.charAt(i)) || Character.isSpaceChar(source.charAt(i))
Is the code you want assuming you DONT want white space characters and only numbers or characters.
Use this condition
for (int i = start; i < end; i++) {
if (!Character.isLetterOrDigit(source.charAt(i))) {
if (!Character.isSpaceChar(source.charAt(i)))
return "";
}
}
精彩评论