小编use*_*611的帖子

使用setFilters时,未正确应用EditText maxLength属性

当我setFilter在a EditText上使用方法来处理特殊字符时,maxLength属性不能按预期工作.我的代码如下.

editName = (EditText)findViewById(R.id.rna_editTextName);
        editName.setFilters(new InputFilter[]{getFilteredChars()}); 


        //Below method returns filtered characters.
       public InputFilter getFilteredChars() 
       {
           InputFilter filter = new InputFilter() 
            { 
                 @Override
                    public CharSequence filter(CharSequence source, int start, int end,                                Spanned dest, int dstart, int dend) {
                        if (end > start) {

                            char[] acceptedChars = new char[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 
                                    'A', 'B', …
Run Code Online (Sandbox Code Playgroud)

android android-edittext input-filter

5
推荐指数
3
解决办法
2769
查看次数

标签 统计

android ×1

android-edittext ×1

input-filter ×1