zoukankan      html  css  js  c++  java
  • ViewPager与Fragment刷新数据

    唉,每次都忘记怎么写,还是老老实实记一下吧!

    public class MDTabViewPagerAdapter extends FragmentStatePagerAdapter {
    
        private static final String TAG = MDTabViewPagerAdapter.class.getSimpleName();
        private List list;
        private FragmentManager fm;
    
        public MDTabViewPagerAdapter(FragmentManager fm, List list) {
            super(fm);
            this.fm = fm;
            this.list = list;
        }
    
        @Override
        public Fragment getItem(int position) {
            Fragment fragment =  (Fragment)list.get(position);
            return fragment;
        }
    
        @Override
        public int getCount() {
            return list == null ? 0 : list.size();
        }
    
        public void setFragments(ArrayList<Fragment> fragments) {
            if ((list == null) && (fm == null) || (fragments == null)) {
                LogUtil.w(TAG, "setFragments is fail. params is null");
                return;
            }
            FragmentTransaction ft = fm.beginTransaction();
            for (int i = 0; i < list.size(); i++) {
                Fragment fragment = (Fragment) list.get(i);
                ft.remove(fragment);
            }
            ft.commit();
            ft = null;
            fm.executePendingTransactions();
    
            this.list.addAll(fragments);
            notifyDataSetChanged();
        }
        /*
            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                Fragment fragment = (Fragment) super.instantiateItem(container, position);
                return fragment;
            }
        
            @Override
            public int getItemPosition(Object object) {
                return POSITION_NONE;
            }
        */
    
    }
  • 相关阅读:
    支付宝支付
    django之contenttype
    vue 项目搭建 及基础介绍
    redis续
    1012
    1009
    灾后重建
    FLOYD判圈
    1007
    1006
  • 原文地址:https://www.cnblogs.com/Mr-Mo/p/4684029.html
Copyright © 2011-2022 走看看