i want to hide keyboard in fragments in android.Because once it displays it remain visible in all fragments.I try this method
public static void hideKeyboard(Context ctx) {
InputMethodManager inputManager = (InputMethodManager) ctx
.getSystemService(Context.INPUT_METHOD_SERVICE);
// check if no view has focus:
View v = ((Activity) ctx).getCurrentFocus();
if (v == null)
return;
inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
and call this method on button click
signIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hideKeyboard(ctx);
login();
}
});
but this give error "java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference"