Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need number only soft keyboard?

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
like image 599
Akh Avatar asked Feb 26 '13 21:02

Akh


2 Answers

By default based on your device, the keyboard shows the special characters too in number keyboard . specifying the Keyboard type for the Text field you can achieve the expected result,such as

 InputFieldName.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);

i.e.

If you need only number included with special characters,then you can use InputType.TYPE_CLASS_NUMBER

or

if you need to exclude those special characters too then use InputType.TYPE_NUMBER_VARIATION_PASSWORD

like image 150
arun Avatar answered Sep 23 '22 07:09

arun


This solution uses numberPassword by overriding the default transformation method for the EditText to show characters instead of dots.

<EditText
    android:id="@+id/userid"
    android:inputType="numberPassword"
    android:maxLength="6"
/>

Add to OnCreate.

// Numeric 6 character user id
EditText input = findViewById(R.id.userid);

// Process input and show characters instead of dots
input.setTransformationMethod(SingleLineTransformationMethod.getInstance());

Numeric soft keyboard Image

like image 23
PDP Avatar answered Sep 24 '22 07:09

PDP