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;
        }

    }

 

发布了19 篇原创文章 · 获赞 9 · 访问量 2万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览