android EditText maxLength not working android EditText maxLength not working android android

android EditText maxLength not working


Try this, it will work for both maxlenght and input filter

month.setFilters(new InputFilter[]{new InputFilterMinMax("0", "12"), new InputFilter.LengthFilter(2)});


Fairly old post but, I noticed how the XML is an actual EditText object, while you are adding the filters to a TextView which could handle it differently than EditText. If you are adding an InputFilter object manually, the xml property is overridden.

The example code on which you add InputFilters to the View seems to be a TextView object. Make sure you pull the right view and it's being cast to EditText if you go with the manual addition of the filters--it's working for me right now.

Good luck.


If you are using InputFilter for the edittext, then maxLength will not work.