验证在编辑文本文本、编辑

由网友(仙女的许愿池)分享简介:我想知道如何使EditText上验证。例如,我有一个EditText上,应该只接受数值。如果不是一个数值以外的其他由用户输入,那么它应该显示一条警告消息(即请用一个数值......)。I would like to know how to make a validation on EditText. For exam...

我想知道如何使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>

的更多信息,请访问: http://developer.android.com/reference/android/widget/EditText.html

More information is available here: http://developer.android.com/reference/android/widget/EditText.html

阅读全文

相关推荐

最新文章