1. 程式人生 > >利用ImageLoader實現imageView快取

利用ImageLoader實現imageView快取

public class MyPagerAdapter extends PagerAdapter {

private List<Lunbo.DataBean> list;
private Context context;

public MyPagerAdapter(List<Lunbo.DataBean> list, Context context) {
    this.list = list;
    this.context = context;
}

@Override
public int getCount() {
    return Integer.MAX_VALUE;
}

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

@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
    int i= position%list.size();
    Lunbo.DataBean dataBean = list.get(i);
    ImageView imageView=new ImageView(context);
    String img = dataBean.getImg();
    ImageLoader.getInstance().displayImage(img,imageView);
    container.addView(imageView);
    return imageView;
}

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

}