Scrollview 内的 Recyclerview 不调用自定义适配器函数 (onBindViewHolder)
Recyclerview inside a Scrollview not calling the Custom Adapter Function (onBindViewHolder)
滚动页面时,onBindViewHolder() 未调用。
由于 Scrollview,mAdapter.notifyDataSetChanged() 未正确更新数据。我在 Recycler 中只选中了 3 个复选框。在加载第二组数据并调用通知程序后,更多的复选框被无关紧要地选中,数据仍然来自模型 class 正确。
出于安全原因,我不能在这里分享代码。
我已经花了一天时间来修复。尚未修复。
然后我尝试删除滚动视图,成功了。
我还有一些视图可以放入滚动条。所以我将其添加为布局并添加到 Recycler 的第一个位置。有效。但是从片段中,每当我只想要它应该到来的时候。至少有什么办法可以解决这个问题。
我认为你应该将 ScrollView
替换为 android.support.v4.widget.NestedScrollView
例如:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" >
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
<!-- Place RecyclerView in here-->
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
@Ogande,谢谢。我试过你的代码。同样的事情正在发生。所以我尝试了不同的解决方案,正如我在问题中提到的那样。
我删除了滚动视图,只保留了 Recyclerview。
我在适配器中添加了两个布局。因此,每当我想添加新布局时,我都会将一个布尔值从片段传递给适配器为 true,并且在开始时所有位置都将默认值为 false。因此 notifychanged()
将反映对具有新布局的适配器的更改。
如我所料,效果很好。
滚动页面时,onBindViewHolder() 未调用。
由于 Scrollview,mAdapter.notifyDataSetChanged() 未正确更新数据。我在 Recycler 中只选中了 3 个复选框。在加载第二组数据并调用通知程序后,更多的复选框被无关紧要地选中,数据仍然来自模型 class 正确。
出于安全原因,我不能在这里分享代码。 我已经花了一天时间来修复。尚未修复。
然后我尝试删除滚动视图,成功了。
我还有一些视图可以放入滚动条。所以我将其添加为布局并添加到 Recycler 的第一个位置。有效。但是从片段中,每当我只想要它应该到来的时候。至少有什么办法可以解决这个问题。
我认为你应该将 ScrollView
替换为 android.support.v4.widget.NestedScrollView
例如:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" >
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
<!-- Place RecyclerView in here-->
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
@Ogande,谢谢。我试过你的代码。同样的事情正在发生。所以我尝试了不同的解决方案,正如我在问题中提到的那样。
我删除了滚动视图,只保留了 Recyclerview。
我在适配器中添加了两个布局。因此,每当我想添加新布局时,我都会将一个布尔值从片段传递给适配器为 true,并且在开始时所有位置都将默认值为 false。因此 notifychanged()
将反映对具有新布局的适配器的更改。
如我所料,效果很好。