private void showSoftKeyboard(View v) {
InputMethodManager imm = (InputMethodManager) getActivity()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
}
private void hideSoftKeyboard() {
InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
.getSystemService(Activity.INPUT_METHOD_SERVICE);
View viewWithCurrentFocus = getActivity().getCurrentFocus();
if (viewWithCurrentFocus != null) {
inputMethodManager.hideSoftInputFromWindow(viewWithCurrentFocus
.getWindowToken(), 0);
}
}
Example:
public static void hideSoftKeyboard(Activity pActivity) {
if (pActivity == null) {
return;
}
InputMethodManager inputMethodManager = (InputMethodManager)
pActivity.getSystemService(Activity.INPUT_METHOD_SERVICE);
View viewWithCurrentFocus = pActivity.getCurrentFocus();
if (inputMethodManager != null && viewWithCurrentFocus != null) {
inputMethodManager.hideSoftInputFromWindow(
viewWithCurrentFocus.getWindowToken(), 0);
}
}