How do I default to numeric keyboard on EditText without forcing numeric input?

Lyudmil picture Lyudmil · May 27, 2011 · Viewed 71.7k times · Source

This has been asked elsewhere online to no avail. Is there any way in Android to display the numeric soft keyboard when focusing on an EditText, but still allow any text to be entered?

I'd like to let the user enter quantities (e.g. "1 kg", "2 L"), so just setting inputType="number" won't work.

Answer

rDroid picture rDroid · Jan 8, 2012

Add the following line of code, and it will do the trick :)

editText.setRawInputType(Configuration.KEYBOARD_QWERTY);

This will show the the numeric keypad first, but also allows you to enter free text.

More information here.