fragment嵌套recyclerview,recyclerview的item重复加载怎么解决

2025-01-26 17:57:50
推荐回答(1个)
回答1:

fragmentManager默认缓存三个页面,即当前和相邻的页面,切到3或4就会导致重新走oncreateview(),数据没清空就重载咯。在@Override
public boolean getUserVisibleHint() {//适用FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();transaction.hide(from).show(to).commitAllowingStateLoss();
return super.getUserVisibleHint();
}
@Override
public void onHiddenChanged(boolean hidden) {//适用于viewpager
super.onHiddenChanged(hidden);
}
进行数据管理