Unable to get maxLength from EditText! (InputFilter.LengthFilter has no length parameter, now what?)

I tried to get EditText filters, but InputFilter.LengthFilter has no LENGTH parameter (or SIZE or something else)!

So, I can not get EditText max length using InputFilter !

Did I miss something? Any suggestions?

+4
source share
2 answers

Why are you trying to “get” the length of InputFilter.LengthFilter? You should already know how long this value is when you set it.

If you need to change it, just reset install the filter and apply it to the EditText view. Again, you know that the length value is set.

0
source

Try creating your own InputLength filter. It will look something like this: (CustomLengthFilter.java) import android.text.InputFilter;

  public class CustomLengthFilter extends InputFilter.LengthFilter { int maxLength; public CustomLengthFilter(int max) { super(max); maxLength = max; } public int get_MaxLength(){ return maxLength; } } 

Then in your editText:

 InputFilter[] inputFilterCollection = this.getFilters(); CustomLengthFilter mCustomLengthFilter = null; for(InputFilter eachInputFilter : inputFilterCollection){ if(eachInputFilter instanceof CustomLengthFilter){ mCustomLengthFilter = (CustomLengthFilter) eachInputFilter; } } if(mCustomLengthFilter != null){ int maxLength = mCustomLengthFilter.get_MaxLength(); } 
0
source

All Articles