Ripple on android.support.v7.widget.CardView when inflating ListView

I am inflating a ListView with a CardView layout :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/lay"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?android:attr/selectableItemBackground"
    android:descendantFocusability="blocksDescendants"
    android:orientation="vertical">
    <android.support.v7.widget.CardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:foreground="?android:attr/selectableItemBackground"
        card_view:cardCornerRadius="2dp"
        card_view:cardElevation="5dp"
        card_view:cardUseCompatPadding="true">

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="10dp">

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <TextView
                android:id="@+id/textView10"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.13"
                android:padding="16dp"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="@color/primary_text" />

            <TextView
                android:id="@+id/textView12"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="112"
                android:layout_marginRight="10dp"
                android:padding="16dp"
                android:paddingLeft="20dp"
                android:text="Small Text"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="@color/secondary_text" />

        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:layout_marginBottom="10dp"
                android:layout_marginTop="10dp"
                android:layout_weight="0.04"
                android:elegantTextHeight="false"
                android:padding="16dp"
                android:paddingBottom="16dp"
                android:paddingLeft="16dp"
                android:paddingRight="16dp"
                android:paddingTop="16dp"
                android:text="Medium Text"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@color/primary_text" />

            <TextView
                android:id="@+id/textView14"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="129"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                android:padding="16dp"
                android:text="Small Text"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textIsSelectable="true" />
        </TableRow>
    </TableLayout>
</android.support.v7.widget.CardView>

and here is my ListView layout :

    <?xml version="1.0" encoding="utf-8"?>
    <ListView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/listView"
            android:visibility="invisible"
            android:paddingBottom="0dp"
            android:background="@color/grey"
            android:layout_gravity="center_horizontal|top"
            android:divider="@color/white"
            android:cacheColorHint="@android:color/transparent"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:fastScrollEnabled="true"
            android:layout_marginRight="0dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

The issue here is that I can't have the ripple effect on the card (I can only have it under the card) as you can see it here : screenshot link

I've tried to put

android:clickable="true"
android:background="?android:attr/selectableItemBackground"

on the cardview, but if I do this, I can't click on the card anymore (the onClick() function doesn't trigger anymore)

Would really appreciate some help understanding this.


ANSWERS:


It looks like you were close by adding the clickable and background, but you likely just need to select the right view to put the onClick listener on.

Did you try this?

view.findViewById(R.id.card_view).setOnClickListener(new View.OnClickListener)

view would be your LinearLayout with the id of lay.



 MORE:


 ? multiple cardview layouts in one recyclerview in a fragment
 ? Error inflating class android.support.v7.widget.CardView?
 ? Change ons-list look and feel to CardView
 ? How we fetch Onclick Button value in Cards recylerView
 ? Android List of CardWithList
 ? How to add custom layout in CardListView for gabrielemariotti cards
 ? Android Cardslib same thumbnail appears for all items
 ? Expandable CardView using Cardslib
 ? In general, how do I use a custom card with a recyclerview?
 ? Different Layouts inside CardsWithList cardslib Library