Android: close keyboard

When I am entering text into EditText and then hitting Save Button I want the keyboard to close.


 closeSoftKeyboard(myEditText);
...
}
private void closeSoftKeyboard(View view) {
   InputMethodManager imm = (InputMethodManager)       getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
   imm.hideSoftInputFromWindow(view.getWindowToken(), 0);

}


getActivity() is needed when you use it in Fragment.

No comments:

Post a Comment