How to show the android numpad on a button click,without using xml.
i know the code for showing simple keyboard that is:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput (InputMethodManager.SHOW_FORCED, 0);
KeyboardMouse.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
But i want to show only numeric keypad instead.
Please help me.
try the following code
EditText ed= (EditText) findViewById(R.id.editeextId);
ed.setInputType(InputType.TYPE_CLASS_NUMBER);
Related
How to open this dialog from my application to change the keyboard.
InputMethodManager imeManager = (InputMethodManager)
getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
imeManager.showInputMethodPicker();
I have an EditText with the ImeOptions set to EditorInfo.IME_ACTION_NEXT. So the "Next" button is displayed on the keyboard when the field is focused.
I want the button to change for "Done" WHILE the user is typing (for some reasons).
So I have a TextWatcher and I try to change the ImeOptions to EditorInfo.IME_ACTION_DONE on "afterTextChanged" but the key on the keyboard doesn't change.
I tried to hide the keyboard, change the ImeOptions and show the keyboard again but it doesn't work (this solution works for iOS).
Does someone know how to do that?
I tried this and it works, the problem is that you can sometime see when the keyboard appears and disappears.
#Override
public void afterTextChanged(Editable s) {
if (/*condition*/) {
// Change the IME of the current focused EditText
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
// Hide the keyboard
hideKeyboard(activity);
// Restart the input on the current focused EditText
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.restartInput(editText);
// Show the keyboard
showKeyboard(activity);
}
}
You can try something like that:
if (your condition) {
youreditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
hideKeyboard(activity);
InputMethodManager input= (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
input.restartInput(youreditText);
showKeyboard(youractivity);
}
From the answers above:
// Restart the input on the current focused EditText
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.restartInput(editText);
Only restarting the input does the trick. Otherwise, presumeably keyboard flickering is to be expected. Input restart also doesn't clear the field's contents i.e. doesn't lead to data loss, which is the desired behavior.
I need to hide the soft keyboard in response to clicking a button.
I saw some posts about this, and I tried it with:
InputMethodManager im = (InputMethodManager) getSystemService(
Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(myEditText1.getWindowToken(), 0);
That worked well. But now I have two EditText views. How can I now hide the soft keyboard, no matter wich EditText is selected? I tried it also with
InputMethodManager im = (InputMethodManager) getSystemService(
Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(myEditText1.getWindowToken(), 0);
im.hideSoftInputFromWindow(myEditText2.getWindowToken(), 0);
, but that didn't worked...
Thanks for your help!
EDIT:
Found solution. Posted below.
Simply you dont need to point specific view. Im using this and works :)
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
A solution is to not get the window token from the EditText, but from the buton wich hides the keyboard itselfs:
InputMethodManager im = (InputMethodManager) getSystemService(
Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(hideKeyboardButton.getWindowToken(), 0);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
You can "play" with the parameter to achieve whatever you want.
Hope this helped!
I'm trying to show the soft input keyboard for a view on the touch event.
This line works:
inputManager.toggleSoftInputFromWindow(getWindowToken(),0,0);
But this line doesn't work:
inputManager.showSoftInput(this,0);
Why is it so? What if I want to connect the soft input to the view?
Thanks.
I think you are testing on emulator. not on real device?
It will not open the keyboard on AVD but it will open on real device, which does not have Hard key board.
To test it on AVD you need to disable the keyboard.
To disable keyboard use
Click on AVD manager > open you targeted AVD > Edit > Hardware > New > Keyboard Support > OK > Make it "NO"
try this:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
try this in onclick event.
InputMethodManager imm =
(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
InputMethodManager.HIDE_IMPLICIT_ONLY);
showSoftInput() won't work unless your View has focus. Moreover, calling requestFocus() does not give your View focus unless you first call setFocusableInTouchMode() and/or setFocusable() to true.
You need to request focus first and show the soft input as follows:
mEditTextStudy.requestFocus();
mEditTextStudy.post(
new Runnable() {
#Override
public void run() {
InputMethodManager imm =
(InputMethodManager)
getActivity()
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.showSoftInput(mEditTextStudy, SHOW_FORCED);
}
}
});
I am using data and time picker for two edit text, I want to hide keyboard for two edit text.I am doing like this
mDatePickerEdt = (EditText)findViewById(R.id.createwedding_datepicker_edt);
mTimePickerEdt = (EditText)findViewById(R.id.createwedding_timepicker_edt);
mDatePickerEdt.setInputType(InputType.TYPE_NULL);
mTimePickerEdt.setInputType(InputType.TYPE_NULL);
it is working for smart phones.I getting problem in samsung galaxy note.If any one have idea.Please help, Thanks in advance.
you can use following code to hide keyboard.
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
try this
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
or try input InputMethodManager.HIDE_NOT_ALWAYS instead of 0
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
you can use below code to suppress the keyboard until the user touched the edittext view.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);