我想知道如何对 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....").
是否有功能可用于确定输入的文本是否为特定类型?如果可能,请附上代码片段.
Is there a function available to find out if the entered text is particular type? If possible please include a code snippet.
与其制作弹出窗口,不如将提示集成到 EditText 中,这样用户只能在 EditText 中键入数字(android:数字,机器人:提示):
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
这篇关于验证编辑文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!