ViewPager and Fragment refresh data, viewpagerfragment

Source: Internet
Author: User

ViewPager and Fragment refresh data, viewpagerfragment

Alas, every time I forget how to write it, remember it honestly!

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.