How do I show the number keyboard on an EditText in android?

Viewed 181350

I just basically want to switch to the number pad mode as soon a certain EditText has the focus.

13 Answers

You can configure an inputType for your EditText:

<EditText android:inputType="number" ... />

Use the below code in java file

editText.setRawInputType(Configuration.KEYBOARD_QWERTY);

Below code will only allow numbers "0123456789”, even if you accidentally type other than "0123456789”, edit text will not accept.

    EditText number1 = (EditText) layout.findViewById(R.id.edittext); 
    number1.setInputType(InputType.TYPE_CLASS_NUMBER|InputType.TYPE_CLASS_PHONE);
    number1.setKeyListener(DigitsKeyListener.getInstance("0123456789”));
Related