![](/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.