![](/img/trans.png)
[英]How to limit the EditText input only allow 3 digits of number either integer or decimal
[英]Limit the number of text in edittext to 13 digits android
如何確保在此edittext上輸入的文本不過是13位數字。 這是我的嘗試,但用戶可以輸入5位數字,但我希望輸入13位數字
<EditText
android:id="@+id/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:maxLength="13"
android:layout_below="@+id/TextView01"
android:layout_centerHorizontal="true"
android:ems="10"/>
更新代碼
final EditText phone = (EditText)findViewById(R.id.phone);
InputFilter[] filterArray = new InputFilter[1];
filterArray[0] = new InputFilter.LengthFilter(11);
phone.setFilters(filterArray);
if(Double.parseDouble(phone.getText().toString()) > 11)
{
//the above if text always fails
}
我不完全知道您想做什么,但是也許您可以嘗試以下方法之一:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.