package com.mints.goodmoney.ui.adapter;

import androidx.viewpager.widget.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

/**
 * 描述：Adapter
 * 作者：孟崔广
 * 时间：2018/3/29 17:51
 * 邮箱：mengcga@163.com
 */
public class ViewPagerAdapter extends PagerAdapter {

    private List<ImageView> mImageViews;

    public ViewPagerAdapter(List<ImageView> mImageViews) {
        this.mImageViews = mImageViews;
    }

    //设置viewpager条目的个数
    @Override
    public int getCount() {
        return mImageViews.size();
    }

    //判断Viewpager的页面的view对象是否和instantiateItem返回的object一致
    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    //添加viewpager条目的方法
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView imageView = mImageViews.get(position);
        //将imageview添加给viewpager
        container.addView(imageView);
        return imageView;
    }

    //销毁viewpager条目的方法
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        //super.destroyItem(container, position, object);
        container.removeView((View) object);
    }
}
