17

I have an EditText with inputMode = text. By default software keyboard is shown as alphabetical and user have to switch it to numeric by pressing specific key (like "123").

Having text inputMode is it possible to show numeric keyboard by default instead of alphabetic?

I need both alphabetic and numeric. But numeric is used more often then alphabetic so i search for way to switch mode programmatically.

Cœur
  • 37,241
  • 25
  • 195
  • 267
user655419
  • 306
  • 5
  • 10
  • I gone rather feel stupid asking this, but why dont you change android:inputType="number" when you obviously expect some number and no alphabet characters? – peter_budo Jan 24 '12 at 14:50

3 Answers3

2

I find the answer a day, finally I found this and its work.

android:inputType="textVisiblePassword"

source

Community
  • 1
  • 1
Zainal Fahrudin
  • 536
  • 4
  • 23
1

Just set it with the normal setter:

    EditText editText = (EditText) findViewById(R.id.edittext);
    editText.setInputType(InputType.TYPE_CLASS_NUMBER);
    // or 
    editText.setInputType(InputType.TYPE_CLASS_TEXT);
Mark
  • 7,507
  • 12
  • 52
  • 88
  • 6
    This sets the type of input to numbers and only numbers. The goal is to allow both numbers and characters, only set the keyboard mode to numbers by default. – Guy Moreillon Feb 03 '14 at 08:15
-3

you can achieve it by setting the below attribute to EditText on xml has follows android:inputType="number"

Senthil Mg
  • 3,301
  • 4
  • 32
  • 49