Closed wuzhuohan7788 closed 10 months ago
public class ImageAdapter extends BannerAdapter<BannerBean, ImageAdapter.ImageViewHolder> { private Context context; private List list;
public ImageAdapter(Context context, List<BannerBean> datas) { super(datas); this.context = context; this.list = datas; } //更新数据 public void updateData(List<BannerBean> data) { //这里的代码自己发挥,比如如下的写法等等 list.clear(); list.addAll(data); notifyDataSetChanged(); } @Override public ImageViewHolder onCreateHolder(ViewGroup parent, int viewType) { ImageView imageView = new ImageView(parent.getContext()); //注意,必须设置为match_parent,这个是viewpager2强制要求的 imageView.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); return new ImageViewHolder(LayoutInflater.from(context).inflate(R.layout.item_advertising_list, parent, false)); } @Override public void onBindView(ImageViewHolder holder, BannerBean data, int position, int size) { Log.i("ImageViewHolder", "onBindView: " + data.imageUrl); Glide.with(holder.itemView) .load(data.imageUrl) .thumbnail(Glide.with(holder.itemView).load(R.drawable.loading)) .apply(RequestOptions.bitmapTransform(new RoundedCorners(30))) .into(holder.imgView); } @Override public int getItemCount() { return list.size(); } class ImageViewHolder extends RecyclerView.ViewHolder { ImageView imgView; public ImageViewHolder(@NonNull View itemView) { super(itemView); imgView = itemView.findViewById(R.id.iv_advertising); } }
}
这是我自定义的Adapter,但是在运行时,发现onBindView他没进来,到时候我界面的轮播图没有效果。我试了你自带的BannerImageAdapter方法,也同样不走onBindView
public class ImageAdapter extends BannerAdapter<BannerBean, ImageAdapter.ImageViewHolder> { private Context context; private List list;
}
这是我自定义的Adapter,但是在运行时,发现onBindView他没进来,到时候我界面的轮播图没有效果。我试了你自带的BannerImageAdapter方法,也同样不走onBindView