I am developing an app, which contains several fragments just like the picture below:
The bottom view is MainActivity
, and there are several fragments above MainActivity
, which may contain buttons. I want to add a fragment on top in order to listen the OnTouchEvents
(gestures), but ignore the onclick
events and pass the onclick
events to the fragments below.
Here are my questions,
- How can I distinguish
onTouchEvent
andonclick
events in my codes? - How can I pass the
onclick
events to the fragments below?
I saw some people suggested to useonInterceptTouchEvent()
, but I am not sure if this applies to my case and I do not really understand how to useonInterceptTouchEvent()
.
Update:
I tried to override boolean dispatchTouchEvent(MotionEvent ev)
to make the top fragment ignore the click event, however since the first touch event must be MotionEvent.ACTION_DOWN
, it seems that there is no way for me to determine whether the touch event is click.
So, is there any other way to do this?