Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 593
Lyudmil Avatar asked May 27 '11 14:05

Lyudmil


People also ask

How do I get just the number keyboard on my Android?

To get the number pad, and tap the special character key in the lower left corner of the keyboard. Then, tap the key just to the left of the spacebar with the numbers 1-4 in a little square. You'll get a cool little number pad along with common mathematical operators.

How can add only numbers in EditText in Android?

You can use android:inputType="number" in the XML file. You can specify other values such as numberDecimal as well. Also, you might additionally want to use android:singleLine="true" for a single line Edittext .


2 Answers

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.

like image 117
rDroid Avatar answered Sep 24 '22 09:09

rDroid


This may be device dependant but have you tried:

 android:inputType="phone" 

All Input Types Link

in the EditText's xml , this gives you the number pad keyboard but then you can still switch to letter's if you want. (Atleast on my Nexus One).

like image 38
Blundell Avatar answered Sep 24 '22 09:09

Blundell