0

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.

T3KBAU5
  • 1,861
  • 20
  • 26
sara roberts
  • 63
  • 1
  • 1
  • 11
  • you need an `InputFilter`. see http://developer.android.com/reference/android/text/InputFilter.html – njzk2 Nov 21 '14 at 20:35

1 Answers1

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