网络请求无限轮播

//轮播 轮播
instance = NetUtils.getInstance();
instance.getService(url, new NetUtils.NetCallBack() {

        @Override
        public void onSuccess(String result) {

            Gson gson = new Gson();
            Log.i(TAG,result);
            LunBean lunBean = gson.fromJson(result, LunBean.class);
            List<LunBean.DataBean> data1 = lunBean.getData();
            for (int i=0;i<data1.size();i++){
                ImageView imageView = new ImageView(getActivity());
                imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                ImageLoader.getInstance().displayImage(data1.get(i).getUrl(),imageView);
                list.add(imageView);
            }
            adapter=new LunAdapter(getActivity(),list);
            viewpager.setAdapter(adapter);
            handler.sendEmptyMessageDelayed(0,2000);
        }
    });

public class LunAdapter extends PagerAdapter {
private Context context;
private List list;

public LunAdapter(Context context, List<ImageView> list) {
    this.context = context;
    this.list = list;
}

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

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

@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
    ImageView imageView = list.get(position % list.size());
    container.addView(imageView);
    return imageView;
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
    container.removeView((View) object);
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值