I get a null pointer exception at this row:
public void hideKeyboard(){
InputMethodManager inputManager = (InputMethodManager)
this.
Just use this one:
public void hideKeyboard(View v){
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
Use this if you are getting error : Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.IBinder android.view.View.getWindowToken()' on a null object reference
InputMethodManager inputMethodManager = (InputMethodManager) MainActivity.this.getSystemService(Activity.INPUT_METHOD_SERVICE);
if(MainActivity.this.getCurrentFocus() != null)
{
inputMethodManager.hideSoftInputFromWindow(MainActivity.this.getCurrentFocus().
getWindowToken(), 0);
}