-8

Possible Duplicate:
Open a numeric keyboard without forcing the EditText to be numeric only

In my app i have an EditText field which accepts only integer values. so i thought it would be better to open the numpad automatically instead of the alphabetics when i click on this EditText.

How can i achieve this??
Community
  • 1
  • 1
Housefly
  • 4,324
  • 11
  • 43
  • 70

3 Answers3

1

in your xml file when defining your EditText, you add your inputType as Number

android:inputType="number"
ColdFire
  • 6,764
  • 6
  • 35
  • 51
0

Using xml layout attributes

For this, you can use several xml attributes to your EditText xml definition (see android:inputType for available options)

Examples:

<EditText android:inputType="phone" ...
<EditText android:inputType="number" ...
<EditText android:inputType="numberSigned" ...
<EditText android:inputType="numberDecimal" ...

You can also both hint android to show digital keyboard and restrict input to acceptable characters with android:numeric

Examples:

<EditText android:numeric="integer" ...
<EditText android:numeric="signed" ...
<EditText android:numeric="decimal" ...

Programatically

Use EditText.setRawInputType(int) with constants such as TYPE_CLASS_NUMBER you will find in android:inputType

or

EditText editView = new EditText(this);
editView.setKeyListener(new NumberKeyListener())

EditText editView = new EditText(this);
editView.setKeyListener(new DigitsKeyListener());

Hope this help

K_Anas
  • 31,226
  • 9
  • 68
  • 81
-1

See TextView Documentation as EditText extends from it :

http://developer.android.com/reference/android/R.styleable.html#AutoCompleteTextView_inputType

ChristopheCVB
  • 7,269
  • 1
  • 29
  • 54