FragmentPagerAdapter 刷新数据
作者:互联网
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万+ 私信 关注
标签:FragmentPagerAdapter,fragmentList,int,fm,刷新,Override,ft,数据,public 来源: https://blog.csdn.net/Sunshine_Cui001/article/details/104006841