public class HomeFragmentPagerAdapter extends FragmentPagerAdapter {
private final FragmentManager fm;
public List<Fragment> fragmentList = new ArrayList<>();
public HomeFragmentPagerAdapter(FragmentManager fm, List<Fragment> fragmentList) {
super(fm);
this.fm = fm;
this.fragmentList = fragmentList;
}
@Override
public Fragment getItem(int arg0) {
return fragmentList.get(arg0);
}
@Override
public int getCount() {
return fragmentList.size();
}
public void refresh(List<Fragment> fragmentList){
if (this.fragmentList!=null){
FragmentTransaction ft = fm.beginTransaction();
for (Fragment fragment : this.fragmentList) {
ft.remove(fragment);
}
ft.commit();
ft = null;
fm.executePendingTransactions();
}
this.fragmentList = fragmentList;
this.notifyDataSetChanged();
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
}
Sunshine_Cui001 发布了19 篇原创文章 · 获赞 8 · 访问量 2万+ 私信 关注