GridView OnClick不工作

时间:2016-02-22 10:09:22

标签: android gridview android-recyclerview onclicklistener

我已经实施了RecyclerView,对于每个recyclerView项目,我都有GridView及其相应的适配器。

当我试图收听recyclerView onClick()项时,它会监听整个区域的click事件,除了gridView所占用的区域或空间。

public ChildViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if(hallNameAdapter != null){
                Adapter adapter = (Adapter) hallName.getTag();
                if(showMovieTimeAdapter != null){
                    adapter.onHallClick();
                }
            }
        }

Child View Holder Xml。

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:background="#FFFFFF"
    android:layout_height="match_parent">
    <com.movie.bms.utils.customcomponents.TextViewRoboto
        android:id="@+id/show_time_fragment_cinema_hall_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20.9dp"
        app:textStyle="roboto_medium"
        android:textSize="16dp"
        android:textColor="#555555"
        android:layout_marginTop="12dp" />
    <LinearLayout
        android:id="@+id/show_time_fragment_images_lin_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="11.3dp"
        android:layout_below="@id/show_time_fragment_cinema_hall_name"
        android:orientation="horizontal">
        <ImageView
            android:id="@+id/show_time_fragment_reserve_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20.9dp" />
        <ImageView
            android:id="@+id/show_time_fragment_m_ticket_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20.9dp"
            />
    </LinearLayout>
    <com.movie.bms.utils.customcomponents.CustomGridView
        android:id="@+id/show_movie_timings_grid_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/show_time_fragment_images_lin_layout"
        android:layout_marginLeft="20.9dp"
        android:layout_marginTop="13.3dp"
        android:verticalSpacing="12dp"
        android:layout_marginRight="10dp"
        android:columnWidth="100dp"
        android:stretchMode="columnWidth"
        android:gravity="center"
        android:horizontalSpacing="10dp"
        android:numColumns="4"
        >
    </com.movie.bms.utils.customcomponents.CustomGridView>
    <View
        android:id="@+id/show_time_fragment_separator"
        android:layout_below="@id/show_movie_timings_grid_view"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginTop="20dp"
        android:background="#79d6d6d6"/>
</RelativeLayout>

任何帮助或建议都将受到赞赏。

1 个答案:

答案 0 :(得分:-1)

RecyclerView没有onItemClickListener之类的listview或gridview

你必须在onCLickListener适配器的viewHolder中设置recyclerview