0

I want to show numerical keyboard when edittext is focused. I tried

myEditText.setInputType(InputType.TYPE_CLASS_NUMBER)

but then it only accepts number as an input and ignores backspace etc.

I just want that numerical keyboard is showed rather than letters

Hamid Shatu
  • 9,664
  • 4
  • 30
  • 41
sparrkli
  • 661
  • 1
  • 7
  • 17

3 Answers3

1

Do it in your xml layout

<EditText
android:id="@+id/myEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number" />
baroni
  • 176
  • 8
1

You do it in two ways.

Do it in your layout

<EditText
        android:id="@+id/edittex"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"/>

Or in your code.

EditText e = (EditText) findViewById(R.id.edittex);
e.setInputType(InputType.TYPE_CLASS_NUMBER);

or if you want anything like dial keypad which will only show you numbers an dwill me able to take input of Int value. try in code

e.setInputType(InputType.TYPE_CLASS_PHONE);

or in layout

android:inputType="phone"
Shekh Shagar
  • 1,305
  • 1
  • 11
  • 22
0

You may use TYPE_CLASS_PHONE, it adds some symbols (#+.), spaces and backspaces.

More infos here: http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_PHONE

tcollart
  • 1,032
  • 2
  • 17
  • 29