//轮播 轮播
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);
}
}