I get a null pointer exception at this row:
public void hideKeyboard(){
InputMethodManager inputManager = (InputMethodManager)
this.
If you want to hide keyboard when touching in the screen, use the below code
@Override
public boolean onTouchEvent(MotionEvent event) {
InputMethodManager imm = (InputMethodManager)this.getSystemService(Context.
INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(this.getWindow().getDecorView().getRootView().getWindowToken(), 0);
return true;
}
If you want to do this in specific view (EditText)
public void hideKeyBoard(EditText edt) {
InputMethodManager imm = (InputMethodManager)this.getSystemService(Context.
INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edt.getWindowToken(), 0);
}
or you can use any View.
To get the current view
imm.hideSoftInputFromWindow(this.getWindow().getDecorView().getRootView().getWindowToken(), 0);