public static void dismissKeyboard(Activity activity){
  View view=activity.getCurrentFocus();
  if (view != null) {
    InputMethodManager inputManager=(InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.hideSoftInputFromWindow(view.getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
  }
}

public static void dismissKeyboard ( Activity activity ) { View view = activity . getCurrentFocus ( ) ; if ( view != null ) { InputMethodManager inputManager = ( InputMethodManager ) activity . getSystemService ( Context . INPUT_METHOD_SERVICE ) ; inputManager . hideSoftInputFromWindow ( view . getWindowToken ( ) , InputMethodManager . HIDE_NOT_ALWAYS ) ; } }
dismiss the soft keyboard if one view in the activity has the focus .
