Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

Is there a way to do this via xml?

like image 940
hpique Avatar asked Jul 19 '10 21:07

hpique


People also ask

How do I limit text editing?

This example demonstrate about How to limit text length of EditText in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do I limit text in TextView?

you can extend the TextView class and overwrite the setText() function. In this function you check for text length or word cound. Better than counting the text length or the word cound a better way would be to use the "maxLines" attribute along with "ellipsize" attribute to attain the desired effect.

What is EMS in TextView?

ems is a unit of measurement. The name em was originally a reference to the width of the capital M. It sets the width of a TextView/EditText to fit a text of n 'M' letters regardless of the actual text extension and text size. Eg : android:ems Makes the EditText be exactly this many ems wide.


1 Answers

Documentation

Example

android:maxLength="10" 
like image 182
Austin Hanson Avatar answered Oct 20 '22 00:10

Austin Hanson