2

Possible Duplicate:
Android How do you set the max number of characters for an EditText

How can I prevent the user from entering more than 4 numbers in edittext ? thanks

Community
  • 1
  • 1
Dev
  • 199
  • 1
  • 3
  • 10

2 Answers2

3

This is fairly easy task that can be learned from documentation, but nevertheless.

The answer to your question consists of two parts:

  1. How to allow user to input digits only
  2. How to restrict field length to maximum of 4 chars.

The first part can be achieved using android:inputType="number". The other one can be achieved by using android:maxLength field. So the final result would be:

<EditText  ...
    android:inputType="number"
    android:maxLength="4"
    android:lines="1"/>
inazaruk
  • 74,247
  • 24
  • 188
  • 156
0

Set the maxLength property of the EditText equal to 4.

Jason Knight
  • 5,824
  • 1
  • 16
  • 14