-2

I have a recycler view, each item of which contains another recycler view. I want a ripple for the parent recycler view item when a user taps on it. The following code creates a ripple when I tap the text view (@id/friend_name) but not when I tap on the friend_expenses recycler view.

I want a ripple when a user touches anywhere on this item (@id/parent_recycler_view_item_layout). Please help.

Parent recycler view item:

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/parent_recycler_view_item_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?selectableItemBackground"
    android:clickable="true"
    android:focusable="true">

    <TextView
        android:id="@+id/friend_name"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="pare"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/friend_expenses"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/friend_name"
        tools:itemCount="3"
        tools:listitem="@layout/group_friend_expense_item" />
</androidx.constraintlayout.widget.ConstraintLayout>

Child recycler view item (@layout/group_friend_expense_item):

<TextView
    android:id="@+id/friend_expense"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

2 Answers2

0

If you want a ripple effect just add this to the target View:

android:foreground="?selectableItemBackground"    //better in foreground not background

And android:clickable="true" may need also (if you don't set any Listener on it).

Sam Chen
  • 2,491
  • 1
  • 17
  • 31
0

I solved the problem by adding a view to parent_recycler_view_item_layout that covers the entire layout. I gave it an elevation of 1dp and added that selectableItemBackground to this view.