6

我想制作一个EditText盒子并TextWatcher用来防止输入特殊字符。

4

1 回答 1

7

这仅用于字符和空格验证...

InputFilter filter = new InputFilter()     
{  
    @Override  
    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)) && !Character.isSpaceChar(source.charAt(i)))
                return "";

        return null;  
    }
};

myTextView.setFilters(new InputFilter[] { filter });
于 2013-04-12T07:57:33.543 回答