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"/>
Its just simple as that.
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 .
No. But what you can do is check in your activity every time the text changes and then do whatever needs to be done when the first symbol is a "0".
Try this,
In XML,
In Java