Need number only soft keyboard?

Akh picture Akh · Feb 26, 2013 · Viewed 14.1k times · Source

Hi I need a soft keyboard with only numeric values 0 to 9 and Enter key. Shouldn't show anything other than these like . , ( ) etc...

enter image description here

I tried several options as suggested here but nothings seems to work for me.

  1. setRawInputType(Configuration.KEYBOARD_QWERTY)
  2. setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED)
  3. setRawInputType(InputType.TYPE_CLASS_NUMBER)
  4. setRawInputType(InputType.TYPE_CLASS_PHONE)

I always have the extra characters show up on the keyboard like:

enter image description here

setRawInputType(Configuration.KEYBOARD_12KEY) shows a keyboard like this:

enter image description here

Would appreciate any help. Thanks in advance.

NOTE:

  • android:minSdkVersion="14": ICS4.0
  • android:targetSdkVersion="17": JB 4.2

Answer

kabuko picture kabuko · Feb 26, 2013

All you can do for standard keyboards is suggest input types. The keyboard can still display or not display whatever keys it wants. If you must have certain keys and only those, you need to create a custom soft keyboard. If it's only for your app, and especially if it's only for one activity, I wouldn't actually implement a standard keyboard, but just use views/buttons that do the appropriate actions.