UMAR UMAR - 4 months ago 51
Android Question

how to hide keyboard after typing in EditText in android?

I have a

TextView
and button aligned to parent's bottom.

When I enter text in it and press the button to save data, the virtual keyboard does not disappear.

Can any one guide me how to hide the keyboard?

Answer

This should work.

InputMethodManager inputManager = 
        (InputMethodManager) context.
            getSystemService(Context.INPUT_METHOD_SERVICE); 
inputManager.hideSoftInputFromWindow(
        this.getCurrentFocus().getWindowToken(),
        InputMethodManager.HIDE_NOT_ALWAYS); 

Just make sure that this.getCurrentFocus() does not return null, which it would if nothing has focus.