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

    }

 

FragmentPagerAdapter 刷新数据FragmentPagerAdapter 刷新数据 Sunshine_Cui001 发布了19 篇原创文章 · 获赞 8 · 访问量 2万+ 私信 关注
上一篇:从模型到应用,一文读懂因子分解机


下一篇:奇奇怪怪的数学问题