Reputation: 2257
I'm trying to implement a number-only EditText field in my app (Android API 23), meaning that I want the number-only keyboard to show-up when the user enters into it.
To do this I have tried setting these attributes on the EditText field...
android:inputType="number"
android:digits="1234567890"
and
android:inputType="phone"
android:digits="1234567890"
but this still brings up the full keyboard.
Any ideas why this is happening?
I'm testing on a Nexus 5x (Android 6.0.1) with the default keyboard
Upvotes: 2
Views: 1054
Reputation: 76
You can handle this programatically. Try doing:
inputType = TYPE_CLASS_NUMBER
or
inputType = TYPE_NUMBER_PHONE
The first one is for number only. The second is for numbers who have the phone number format.
Upvotes: 0
Reputation: 2257
Problem is I had the EditText inside a ListView. Which is problematic for some reason.
I fixed it by setting the ListView like this
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:descendantFocusability="afterDescendants"
android:focusable="false" />
This helped me lead to the answer EditText inside ListView will not stay focused
Upvotes: 1
Reputation: 1211
Try this.
<EditText
android:digits="0123456789"
android:inputType="numberDecimal"
/>
Upvotes: 2