viewPager适配器封装

QuickFragmentPageAdapter

public class QuickFragmentPageAdapter extends FragmentStatePagerAdapter {
    private List list;

    public QuickFragmentPageAdapter(FragmentManager fm, List list) {
        super(fm);
        this.list = list;
    }

    @Override
    public Fragment getItem(int position) {
        return list.get(position);
    }

    @Override
    public int getCount() {
        return list.size();
    }
}

QuickPageAdapter

public class QuickPageAdapter extends PagerAdapter {
    private List list;

    public QuickPageAdapter(List list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        container.addView(list.get(position));
        return list.get(position);
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView(list.get(position));
    }
}

你可能感兴趣的:(viewPager适配器封装)