运行结果:

代码:
HomoePagerFragment添加内容
protected void initView(View view) {
……………………
// 创建轮播图的适配器
mLooperPagerAdapter = new LooperPagerAdapter();
// 设置设配器
looperPager.setAdapter(mLooperPagerAdapter);
}
public void onLooperListLoaded(List<HomePagerContent.DataBean> loopData) {
mLooperPagerAdapter.setData(loopData);
}
LooperPagerAdapter
public class LooperPagerAdapter extends PagerAdapter {
private List<HomePagerContent.DataBean> mData = new ArrayList<>();
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
HomePagerContent.DataBean data = mData.get(position);
String coverUrl = UrlUtils.getCoverPath(data.getPict_url());
// 自己写布局
ImageView iv = new ImageView(container.getContext());
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
iv.setLayoutParams(layoutParams);
iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
Glide.with(container.getContext()).load(coverUrl).into(iv);
container.addView(iv);
return iv;
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}
@Override
public int getCount() {
return 0;
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}
public void setData(List<HomePagerContent.DataBean> loopData) {
mData.clear();
mData.addAll(loopData);
//注:此处可以打印出loopData
notifyDataSetChanged();
}
}
返回mData.size吧