开发者

Android-Prevent the user from entering more than 4 numbers in editbox [duplicate]

This question already has answers here: Closed 11 years ago.

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:

  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"/>


Set the maxLength property of the EditText equal to 4.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜