AndreaF
AndreaF

Reputation: 12375

How to close momentarily the android keyboard whatever EditText currently active

I have a form with various EditText and a confirm button, I need that when the user click confirm whatever is the EditText that is currently used the keyboard will be momentarily closed, but if the user try to edit again one of the EditText the keyboard appears again.

How could I do this without add tons of codelines to control each EditText separately?

Upvotes: 0

Views: 65

Answers (2)

Nadir Belhaj
Nadir Belhaj

Reputation: 12063

use simply the InputMethodManager

this way

InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

Upvotes: 1

Kamal
Kamal

Reputation: 1415

 InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
                //Find the currently focused view, so we can grab the correct window token from it.
 View view = getCurrentFocus();
//If no view currently has focus, create a new one, just so we can grab a window token from it
 if(view == null) {
    view = new View(this);
 }
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);

This will close the keybord, though i am not sure if keyboard will open gain for the same edit text, haven't tried that.

Upvotes: 0

Related Questions