I have an EditText where the user can enter three words. How do I prevent the user from entering more words? The user also has to be able to erase what they've entered and enter three new words.
Asked
Active
Viewed 52 times
0
-
you need an `InputFilter`. see http://developer.android.com/reference/android/text/InputFilter.html – njzk2 Nov 21 '14 at 20:35
1 Answers
0
try using this in your xml :
<EditText
...
android:maxLength="3" />
or this in your java code :
EditText input = (EditText) findViewById(R.id.your_editTextId);
InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.LengthFilter(3);
input.setFilters(FilterArray);

Mohammad Rahchamani
- 5,002
- 1
- 26
- 36