验证在编辑文本 [英] Validation on Edit Text
问题描述
我想知道如何使EditText上验证。例如,我有一个EditText上,应该只接受数值。如果不是一个数值以外的其他由用户输入,那么它应该显示一条警告消息(即请用一个数值......)。
I would like to know how to make a validation on EditText. For example, I have one EditText that should only accept numeric values. If something other than a numeric value is typed by the user then it should show an alert message (i.e. "please use a numeric value....").
有一个函数可用来找出如果输入的文本是特殊类型的?如果可能的话,请包括code段。
Is there a function available to find out if the entered text is particular type? If possible please include a code snippet.
推荐答案
而不是做一个弹出我会暗示融入的EditText,我会让它这样用户只能输入数字到的EditText(机器人:数字,机器人:提示):
Rather than make a pop-up I would integrate a hint into the EditText and I would make it so the user could only type numbers into the EditText (android:numeric, android:hint):
<EditText android:layout_height="wrap_content"
android:numeric="integer"
android:hint="@string/numberHint"
android:gravity="left"
android:id="@+id/name"
android:layout_width="wrap_content"
android:maxWidth="60dp"
android:textSize="6pt">
</EditText>
的更多信息,请访问: <一href="http://developer.android.com/reference/android/widget/EditText.html">http://developer.android.com/reference/android/widget/EditText.html
More information is available here: http://developer.android.com/reference/android/widget/EditText.html
这篇关于验证在编辑文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!