回收站视图中的行项目不响应点击事件cardview

时间:2015-11-23 08:13:30

标签: android android-recyclerview

我有一个带有CardView的RecyclerView,问题是点击不响应(除非我按下视图的底部)。我设置了clickable =" true" 但它没有帮助

这是我的row_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    card_view:cardCornerRadius="5dp"
    android:clickable="true"

    card_view:cardUseCompatPadding="true" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:foreground="?selectableItemBackground"
    android:clickable="true">

    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/tv_name"
        android:gravity="center"
        android:padding="10dp"
        android:textColor="@color/material_deep_teal_200"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="true"/>

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:id="@+id/cb_check_box"
        android:gravity="right"
        android:layout_centerVertical="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="number"
        android:clickable="true"
        android:id="@+id/tv_number"
        android:layout_below="@+id/tv_name"
        android:layout_centerHorizontal="true" />

</RelativeLayout>
</android.support.v7.widget.CardView>

这就是我设置onClick的方式:

  // Create new views (invoked by the layout manager)
    @Override
    public CustomViewHolder onCreateViewHolder(ViewGroup parent,
                                               int viewType) {
        // create a new view
        View v = LayoutInflater.from(getActivity())
                .inflate(R.layout.contacts_list_item, parent, false);
        // set the view's size, margins, paddings and layout parameters

        v.setOnClickListener(this);

        CustomViewHolder vh = new CustomViewHolder(v);

        return vh;
    }

0 个答案:

没有答案