Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Display Numeric Keypad on Button Click

In my application, I am trying to display the numeric keypad when the user clicks on a button.

When the button is clicked, I shift the focus to the EditText in my layout using requestFocus() and next I need to display the numeric keypad so that the user can type in the values..

The values will always be numeric and hence I need to show only the numeric keypad.

I tired using this inside my button's onClick() method but it does not work.

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

Please provide me with any solution to this.

Also, my application is for an Android tablet supporting 4.0.3.

like image 623
Swayam Avatar asked Dec 16 '22 22:12

Swayam


2 Answers

This one in your EditText property

android:inputType="phone" (This will displayed phone numeric keypad)

or

android:inputType="number" (This will displayed numeric keypad)

Now, you have to just set Focus on your EditText on Button's click..

something like,

edtNumber = (EditText) findViewById(R.id.number);

// Button's onClick....
@Override
 public void onClick(DialogInterface dialog, int which)
  {
    edtNumber.requestFocus();
  }
like image 68
user370305 Avatar answered Dec 18 '22 12:12

user370305


in EditText put below line.

android:inputType="number"
like image 30
Nikhil Avatar answered Dec 18 '22 11:12

Nikhil