When I use setFilter
method on an EditText
to handle special characters, maxLength
property is not working as expected. My code is be
This is because the maxLength
property sets an InputFilter
on your EditText
. By calling EditText.setFilters(new InputFilter[] {
you are overriding all existing InputFilters including the one used by maxLength
.
To fix this, copy the array returned by EditText.getFilters()
and add your own to it:
InputFilter[] editFilters = edit.getFilters();
InputFilter[] newFilters = new InputFilter[editFilters.length + 1];
System.arraycopy(editFilters, 0, newFilters, 0, editFilters.length);
newFilters[editFilters.length] = ;
edit.setFilters(newFilters);