开发者

Android: input type for only non-numeric chars

I have an EditText on wh开发者_JAVA技巧ich I would like to let user enter only non-numeric chars (say A-Z or a-z): is there a way to do it? All the combinations I used (text, textPersonName and so on) let the user select also numbers.


I think you have to write your own InputFilter and add it to the set of filters for the EditText. Something like this might work:

InputFilter filter = new InputFilter() { 
    public CharSequence filter(CharSequence source, int start, int end, 
        Spanned dest, int dstart, int dend)
    {
        for (int i = start; i < end; i++) { 
            if (!Character.isLetter(source.charAt(i))) { 
                return ""; 
            }
        }
        return null; 
    } 
}; 
edit.setFilters(new InputFilter[]{filter});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜