I tried to get EditText
's filters, but InputFilter.LengthFilter
does not have a LENGTH (or SIZE, or something) parameter!
So, I can't get EditText
max length using InputFilter
!
Am I missing anything? Any suggestions?
I tried to get EditText
's filters, but InputFilter.LengthFilter
does not have a LENGTH (or SIZE, or something) parameter!
So, I can't get EditText
max length using InputFilter
!
Am I missing anything? Any suggestions?
Why are you trying to "get" the length of the InputFilter.LengthFilter? You should already know what length it is when you set it.
If you need to change it, just reset the filter and apply it to your EditText view. Again, you would know what the length value is set to.
Try creating a custom InputLength filter. This 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();
}