public void hideKeyboard(View view) {
Context context = view.getContext();
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
// call from inside an Activity / Fragment
hideKeyboard(view);