How do you set the max number of characters for an EditText in Android?

barcodereader picture barcodereader · May 20, 2011 · Viewed 103.4k times · Source

How do you set the max number of characters for an Android EditText input? I see setMaxLines, setMaxEMS, but nothing for the number of characters.

Answer

Massimo Variolo picture Massimo Variolo · Aug 2, 2011

In XML you can add this line to the EditText View where 140 is the maximum number of characters:

android:maxLength="140"