【发布时间】:2020-07-29 15:39:12
【问题描述】:
我有一个 recyclerView,我在 ViewHolder 类中为其子级实现了一个监听器,如下所示:
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun binding(model: NewsAdapterModel) {
itemView.setOnClickListener {
onClick.onClick(model.id)
}
}
并将此代码用于我的 onBindViewHolder:
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.binding(items[position])
}
这也是我的 xml 代码,其中包含 recyclerView 和 SwipeRefreshLayout:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".main.news.NewsFragment">
<ProgressBar
android:id="@+id/loading"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="visible"
app:layout_constraintTop_toTopOf="parent" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loading">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/loading" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
</layout>
我的问题是,一旦我将我的 recyclerView 放入 Swipe Refreshing 布局,recycler 视图的项目就不再可点击。当我删除滑动刷新布局时,它再次变为可点击, 我该如何解决这个问题?
【问题讨论】:
-
尝试同时设置 swiperefresh 和 recyclerView matxh 父项
-
@Rinat,不,没有任何改变
-
这可能听起来很愚蠢,但你永远不会知道.. 尝试将 android:clickable="false" 添加到 swiperefreshLayout
标签: android kotlin android-recyclerview swiperefreshlayout