Since dispatchTouchEvent() is the first method called when a touch happens on a screen , you need to find whether the touch falls within the bound of your edit text view. You can get the touch point as, int x = ev.getRawX(); int y = ev.getRawY();
method to check whether it falls within the bounds of editText
boolean isWithinEditTextBounds(int xPoint, int yPoint) {
int[] l = new int[2];
editText.getLocationOnScreen(l);
int x = l[0];
int y = l[1];
int w = editText.getWidth();
int h = editText.getHeight();
if (xPoint< x || xPoint> x + w || yPoint< y || yPoint> y + h) {
return false;
}
return true;
}
In your onDispatchTouch() do.
if(isWithinEditTextBounds(ev.getRawX,ev.getRawY))
{
//dont hide keyboard
} else {
//hide keyboard
}