简体   繁体   English

Android:仅适用于非数字字符的输入类型

[英]Android: input type for only non-numeric chars

Hello i have an EditText on which i would like to let user enter only non-numeric chars (say AZ or az): is there a way to do it? 您好,我有一个EditText,我想让用户仅输入非数字字符(例如AZ或az):有没有办法做到这一点? All the combinations i used (text,textPersonName an so on) let the user select also numbers. 我使用的所有组合(text,textPersonName等)都允许用户选择数字。

Thanks in advance c. 在此先感谢c。

I think you have to write your own InputFilter and add it to the set of filters for the EditText. 我认为您必须编写自己的InputFilter并将其添加到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});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM