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....").
是否有功能可用于确定输入的文本是否为特定类型?如果可能,请附上代码片段.
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
这篇关于验证编辑文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:验证编辑文本
基础教程推荐
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
