机器人:在编辑文本中的第一个数字不能为零 [英] android: the first digit in the edit text can not be zero

查看:185
本文介绍了机器人:在编辑文本中的第一个数字不能为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数字输入类型一个EditText元素。我不希望用户能够进入0作为第一个数字。我可以强制执行这个使用XML?

下面是我目前:

 <的EditText
                机器人:ID =@ + ID / main_edt_loan
                机器人:layout_width =FILL_PARENT
                机器人:layout_height =40dip
                机器人:背景=@绘制/ sample_editbox
                机器人:EMS =10
                机器人:layout_margin =10dip
                安卓的inputType =数字
                机器人:提示=
                机器人:ellipsize =开始
                机器人:MAXLINES =1
                机器人:imeOptions =actionNext
                机器人:TEXTSIZE =18dip
                机器人:比重=中心
                机器人:位数=0123456789
                机器人:最大长度=10
                机器人:文字颜色=#000000/>


解决方案

有是在其中您可以使用afterTextChange方法。如果长度为1和字符串为0比0删除里面可编辑文本的textWatcher。检查长度的另一种方式。

I have an EditText element with a number input type. I don't want users to be able to enter 0 as the first digit. Can I enforce this using XML?

Here is what I have currently:

<EditText 
                android:id="@+id/main_edt_loan"
                android:layout_width="fill_parent"
                android:layout_height="40dip"
                android:background="@drawable/sample_editbox"
                android:ems="10"
                android:layout_margin="10dip"
                android:inputType="number"
                android:hint=""
                android:ellipsize="start" 
                android:maxLines="1"
                android:imeOptions="actionNext"
                android:textSize="18dip"
                android:gravity="center"
                android:digits="0123456789"
                android:maxLength="10"
                android:textColor="#000000"/>

解决方案

There is an alternative way in which you can use textWatcher .Check length of editable text inside afterTextChange method .if length is 1 and string is 0 than remove 0 .

这篇关于机器人:在编辑文本中的第一个数字不能为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆