【问题标题】:GridView OnClick Not WorkingGridView OnClick 不工作
【发布时间】:2016-02-22 10:09:21
【问题描述】:

我已经实现了 RecyclerView,对于每个 recyclerView 项目我都有 GridView 和它对应的适配器。

当我尝试监听 recyclerView onClick() 项目时,它会监听整个区域的点击事件,但 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();
                }
            }
        }

子视图持有人 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>

对此的任何帮助或建议将不胜感激。

【问题讨论】:

  • 请发布一些相关的代码块。
  • 查看 this 链接在这里解决了
  • 这段代码是我的 RecyclerViewHolder 类的一部分,它实现了 View.OnClickListener()。

标签: android gridview android-recyclerview onclicklistener


【解决方案1】:

RecyclerView 没有 onItemClickListener 像列表视图或网格视图

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

【讨论】:

  • RecyclerView.ViewHolder 也没有onClickListener
  • 我说你必须将它设置在 viewHolder 而不是 ViewHolder 上
  • 感谢您的指出。但我只在回收器视图适配器中实现了 viewHolder 上的监听器。我认为这很明显,所以我没有在我的问题中提到它。
  • 你为什么这么明显
  • 请发布您的 childholder xml 布局代码,可能是 xml 问题
猜你喜欢
  • 1970-01-01
  • 2016-06-05
  • 2012-10-25
  • 1970-01-01
  • 2016-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多