开发者

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 "";
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜