Мне нужно использовать два RecyclerView с разными адаптерами в одном и том же виде.
Мой первый RecyclerView загрузится только один раз в onCreate.
Мой второй RecyclerView будет загружать все больше и больше данных, когда пользователь прокрутите вниз и вызовите API для получения новых данных.
Когда я позволю моему Second RecyclerView вызывать API для загрузки большего и большего количества данных, он будет загружаться очень медленно и интенсивно прокручиваться.
Как могу я это исправить, спасибо!
Вот мой фрагмент:
public class NewFragment extends Fragment {
private void setRecyclerAndAdapter(){
if(swipeRefreshLayout != null && postRecycler != null){
layoutManager = new LinearLayoutManager(context);
postRecycler.setLayoutManager(layoutManager);
LayoutAnimationController animationController = AnimationUtils.loadLayoutAnimation(context, R.anim.layout_animation_up_to_down);
postRecycler.setLayoutAnimation(animationController);
if(postAdAdapter == null){
postAdAdapter = new PostCardAdapter(context, postDataList);
postRecycler.setAdapter(postAdAdapter);
setListener();
}else{
postAdAdapter.notifyDataSetChanged();
}
}else
return;
}
.
private void setListener(){
if(swipeRefreshLayout != null && postRecycler != null){
......
nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if(v.getChildAt(v.getChildCount() - 1) != null) {
if ((scrollY >= (v.getChildAt(v.getChildCount() - 1).getMeasuredHeight() - v.getMeasuredHeight())) &&
scrollY > oldScrollY) {
visibleItemCount = layoutManager.getChildCount();
totalItemCount = layoutManager.getItemCount();
pastVisiblesItems = layoutManager.findFirstVisibleItemPosition();
if(controlCanGetMorePostData == true){
controlCanGetMorePostData = false;
if(postAdAdapter != null){
if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
postAdAdapter.setLoadState(postAdAdapter.LOADING);
callApiManagerGetMoreData();
}
}else
return;
}
else{
hasMorePostData = false;
setMoreDataState();
}
}
}
}
});
}else
return;
}
}
Вот мой макет:
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_new_swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:id="@+id/fragment_new_nestedScroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none">
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="1"
android:rowCount="2">
<RelativeLayout
android:id="@+id/fragment_new_banner_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_row="0">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/fragment_new_first_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
<com.gmpsykr.each.Game.BannerIndicator
android:id="@+id/fragment_new_banner_indicator"
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_alignBottom="@+id/fragment_new_banner_recycler"
app:selectColor="@color/colorAccent"
app:unselectedColor="#ffffff"
app:radius="3dp"
app:space="10dp" />
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/fragment_new_second_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutAnimation="@anim/layout_animation_up_to_down"
android:layout_row="1" />
</GridLayout>
</androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>