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
这篇关于验证编辑文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:验证编辑文本


- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01