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

    }

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页