13

I am developing an android application where we are using WebView to display Web page being served from Web Server. Everything is working fine except with the problem that when i am using the soft keyboard and switched to numeric key entry and move from first field to next field, the keyboard layout automatically changed to alphanumeric.

Is there any way using which i can pull up virtual keyboard in numeric mode only when i need to enter numbers only?

Thanks and Regards.

Whitewall
  • 597
  • 1
  • 7
  • 18
Shivaansh Gupta
  • 131
  • 1
  • 1
  • 3

4 Answers4

28
editTextField.setRawInputType(Configuration.KEYBOARD_QWERTY);

This shows the normal key pad with the numeric version first, yet allows you to switch between them.

getInput.setRawInputType(Configuration.KEYBOARD_12KEY);

This shows numeric only, with no option to enter text values.

I ran into a similar situation. I wanted numeric values only, but I have a "hint" that was text. Setting the inputType to number would not allow the hint to be displayed. This works around it fine.

kapex
  • 28,903
  • 6
  • 107
  • 121
user455451
  • 313
  • 3
  • 3
  • 5
    shouldn't you use InputType.TYPE_CLASS_NUMBER instead of Configuration.KEYBOARD_QWERTY, and InputType.TYPE_CLASS_PHONE instead of Configuration.KEYBOARD_12KEY? these are the same int values so has the same affect, but I think these are the correct types. – SteelBytes Mar 12 '11 at 04:29
  • user455451, I have the same problem and I've tried your method. Unfortunately, it doesn't work: if I use TYPE_CLASS_NUMBER (or Configuration.KEYBOARD_QWERTY - codes are the same) I get numeric keypad WITHOUT possibility to switch it to text input. Maybe the problem is in Android? I have 2.1 version. – Mr.D Feb 22 '12 at 17:14
  • Configuration.KEYBOARD_QWERTY constant is number 2 - the same as TYPE_CLASS_NUMBER. Most of soft inputs does not allow to switch from number mode to alphanumeric mode. Even when some of them do - pressing on letter keys have no effect. – Michael P Jan 29 '15 at 07:52
2

Configuration.KEYBOARD_12KEY or Configuration.KEYBOARD_QWERTY is wrong way.

You have to use InputType (show doc here) on the EditText setRawInputType().

Renjith K N
  • 2,613
  • 2
  • 31
  • 53
1

If you are talking about HTML, you could use HTML5 features, for example:

Number: <input type="number" name="points" min="1" max="10" />

Have tested this in HTC Desire browser, and it brings up different (numeric) keyboard when you enter data into such field.

altumano
  • 2,676
  • 2
  • 26
  • 20
  • Yes, this should work in many circumstances. However, if you happen to use jQueryMobile for your HTML5 browser app, type=number does not trigger a numeric keyboard. – Wytze Jun 29 '12 at 07:51
  • For my PhoneGap app, specifying type="number" only brought up the numeric keyboard after the user had entered one character. This jQuery fixed that for me (where all such inputs have a class of pin): $(".pin").live('tap', function() { $(this).focus(); }); – David Conlisk Sep 07 '12 at 13:24
0

Is there any way using which i can pull up virtual keyboard in numeric mode only when i need to enter numbers only?

Yes, you can specify android:inputType XML attribute with the number or numberDecimal value:

<EditText 
android:text="" 
android:id="@+id/editTextNumber" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:inputType="numberDecimal">
</EditText>

Enjoy!!

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295