Android-Prevent the user from entering more than 4 numbers in editbox [duplicate]
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 editte开发者_运维问答xt ? thanks
This is fairly easy task that can be learned from documentation, but nevertheless.
The answer to your question consists of two parts:
- How to allow user to input digits only
- 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"/>
Set the maxLength
property of the EditText equal to 4.
精彩评论