如何验证EditText仅在Android中处理数字? [英] How To Validate an EditText to handle numbers only in Android ?
本文介绍了如何验证EditText仅在Android中处理数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好:)
如何验证android中的文本视图以处理正整数?
我不希望它接受任何字符或符号等...
谢谢大家
Hello :)
How can I validate a text view in android to handle positive integer numbers ?
I don''t want it to accept any character or signs etc...
thank you all
推荐答案
这可能解决了您的问题
方法1:
TextView txt =(TextView)findViewById(R.id.txtview);
txt.setInputType(InputType.TYPE_CLASS_NUMBER);
方法2:在XML文件中
添加此行
< textview>
android:id ="@ + id/txtview"
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:ddigits ="0123456789"
android:text ="@ string/hello"/>
This may be solve ur problem
Method 1:
TextView txt=(TextView)findViewById(R.id.txtview);
txt.setInputType(InputType.TYPE_CLASS_NUMBER);
Method2: in XML file
add this line
<textview>
android:id="@+id/txtview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ddigits="0123456789"
android:text="@string/hello" />
我找到了解决办法,
通过在您的编辑文本中添加:android:inputType ="number"
I found the selution,
by adding: android:inputType="number" to your Edit text
这篇关于如何验证EditText仅在Android中处理数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文