Android: input type for only non-numeric chars

后端 未结 1 442
不知归路
不知归路 2021-01-16 10:38

Hello i have an EditText on which 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,textPers

相关标签:
1条回答
  • 2021-01-16 11:01

    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 讨论(0)
提交回复
热议问题