Is it possible to make a RecyclerView
not clickable? I want this because my RecyclerView
just shows some small icons, within a clickable CardView
. So if someone taps the icons, it should just click (and animate) the parent CardView
instead.
I have tried the following:
recyclerView.setClickable(false);
recyclerView.setFocusable(false);
- Extend
RecyclerView
and makeonTouchEvent(MotionEvent)
returnfalse
. - Use method 3 above and use
itemView.setClickable(false);
in theRecyclerView
Adapter. This works, the click is sent to the parent. However, now theRecyclerView
is not scrollable anymore. - Set
clickable="false"
,focusable="false"
,focusableInTouchMode="false"
in inflated list item XML. (See comment @Ibrahim) - Call
recyclerView#setLayoutFrozen(true)
anditemView.setClickable(false);
. This works, but has the same issue as #4.
Any ideas how to disable and pass through the click events of the RecyclerView
to the parent view? Note that the RecyclerView
still needs to be scrollable (horizontal).
EDIT:
User @c.dunlap suggested to set OnClick listeners to the icons, and just "redirect" the click to the parent's click action. This would work, but there won't be a click animation on the parent view. And if someone clicks outside an itemView - but still inside the RecyclerView
(e.g. ItemDecoration padding) - the click is not detected. So unfortunately this is not a solution.