@Override public boolean dispatchTouchEvent(MotionEvent ev) { // Do some custom touch event handling logic here // ... // Call super so that child views can also handle the event return super.dispatchTouchEvent(ev); }
private class CustomView extends View { @Override public boolean dispatchTouchEvent(MotionEvent ev) { Log.d("CustomView", "Touch event received: " + ev.getAction()); return super.dispatchTouchEvent(ev); } }Here we have a custom View class that logs touch events received by this View. We override the dispatchTouchEvent method to log the action of the MotionEvent received by this View. We then call the superclass's implementation of the method to allow child views to also handle the touch event.