Android

Set maxLength of EditText dynamically

Set maxLength of EditText dynamically

At times you may want to set maxlength of EditText view dynamically.

maxLength

You’ve to use setFilters method of EditText, as shown below.

EditText et = new EditText(this);
int maxLength = 3;
InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.LengthFilter(maxLength);
et.setFilters(FilterArray);

Hope it helps somebody…
Cheers 🙂

You may be also interested in

Leave a Reply

Your email address will not be published. Required fields are marked *