Limit text length of EditText in Android


Question

What's the best way to limit the text length of an EditText in Android?

Is there a way to do this via xml?

1
637
7/19/2010 9:55:42 PM

Accepted Answer

Documentation

Example

android:maxLength="10"
1263
12/15/2015 4:48:52 PM

use an input filter to limit the max length of a text view.

TextView editEntryView = new TextView(...);
InputFilter[] filterArray = new InputFilter[1];
filterArray[0] = new InputFilter.LengthFilter(8);
editEntryView.setFilters(filterArray);

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon