I am trying to capture the clicks on ImageView
which is enclosed inside the RecyclerView
item. I have implemented RecyclerView.OnItemTouchListener
and has gesture detector process the motion events for normal clicks and long press on RecyclerView
item.
Since I want to have the same touch framework to process touch event on child views inside the RecylcerView
item, I have set View.OnTouchListener
with the image view as well, overriding the onTouch
implementation returning true hoping that the touch shall be consumed by the ImageView
when it gets clicked.
I am intentionally returning false in onInterceptTouchEvent
always from the RecyclerView
, hoping the child views process the event first and if none of them consumes then RecyclerView
's item view shall handle the gesture event for clicks during onTouchEvent
handling.
With the above understanding I am able to receive touch events on the ImageView
when clicked on it.
The problem is that, when I click on the RecyclerView
item outside ImageView
, RecyclerView
's onTouchEvent
is not getting called at all. my understanding of the touch framework is that if child views doesn't process the touch event, the RecyclerView
's onTouchEvent
should get a chance to process the same. However this is not what i am able to achieve.
Can anyone suggest what is happening behind and what is the correct way to process click events for the above?
This will solve your problem:
Get an instance of 'OnItemClickCallback' interface and put it in your activity or fragment:
Then, pass that callback to your recyclerView:
Finally, this would be your adapter: