唉,每次都忘记怎么写,还是老老实实记一下吧!
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; } */ }
时间: 2024-10-06 08:00:06