限制在一个EditText非小数位数 [英] Limit the number of non decimal digits in an edittext
本文介绍了限制在一个EditText非小数位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个EditText中,我只须输入数字低于10000 9999.99是一个有效的条目,但10000不是。有没有什么办法来限制数字在mantessa部分号码
I have an edittext in which I have to enter only digits below 10000. 9999.99 is a valid entry but 10000 is not. Is there any way to limit the number of digits in the mantessa part
推荐答案
添加这行 Android版本:数字=整数
,并采取TextWatcher签总量值小于; 10000
add this line android:numeric="integer"
and take a TextWatcher check total value< 10000
<EditText android:numeric="integer"... />
edittext.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
float final =Float.valueOf(s.toString());
if(final<10000)
//accept
else
//reject
}
});
这篇关于限制在一个EditText非小数位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文