Reputation: 139
I have a View that has a button. On the button click, I want the soft keyboard to pop up with numbers. I can use toggleSoftInput, however, I see no way to change the input type.
public class TimerOnClickListener implements View.OnClickListener {
@Override
public void onClick( View view ) {
Context context = view.getContext();
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput( 0, 0 );
}
}
How can I toggle the input with numbers only?
Upvotes: 0
Views: 816
Reputation: 516
Make sure you set your view in XML to a number:
android:inputType="number"
that should force the keyboard to be numeric.
Upvotes: 0
Reputation: 643
Following code will display keypad to you:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, 0);
However if you want to force the keyboard that appears into being the Number or telephone keypad, then you have to set the input type on that particular view/widget.
InputType.TYPE_CLASS_NUMBER;
InputType.TYPE_CLASS_PHONE;
eg.
your_edit_text.setInputType(InputType.TYPE_CLASS_NUMBER);
Credits: Ritesh Gune InputMethodManager show numpad in webview
Upvotes: 3
Reputation: 932
Check this answer:
set inputType to your EditText to "number"
To show the keyboard:
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(editText, 0);
Upvotes: 0