Reputation: 15
I need to apply an input Type a editText
from Java. What I need is to provide the numeric keypad to enter a phone number. I can not apply the inputType in the xml layout because the editText is dynamically generated.
I tried it with:
editText.setInputType(InputType.TYPE_CLASS_PHONE);
but it is not working properly, does not give me the numeric keypad.
Upvotes: 1
Views: 319
Reputation: 1114
Set property in XML like this:
<EditText
android:id="@+id/myNumber"
android:digits="0123456789."
android:inputType="numberDecimal"
/>
OR you can use:
android:inputType="number"
Upvotes: 1
Reputation: 204
For setting the input type for an EditText programatically you have to specify that input class type is text like:
editText.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
Upvotes: 1