使用我当前的设置,它会导致RecyclerView滞后,因为我有很多资源图像。如何在我的ViewHolder中使用Glide加载图像数组而不是 holder.item_img.setImageResource(INF.getImage_id()); ?
ArrayList<Information> information = new ArrayList<Information>();
Context ctx;
public InformationAdapter(ArrayList<Information> information, Context ctx)
{
this.information = information;
this.ctx = ctx;
}
@Override
public InformationViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view_layout,parent,false);
InformationViewHolder informationViewHolder = new InformationViewHolder(view,ctx,information);
return informationViewHolder;
}
@Override
public void onBindViewHolder(InformationViewHolder holder, int position) {
Information INF = information.get(position);
holder.item_img.setImageResource(INF.getImage_id());
holder.item_name.setText(INF.getName());
holder.item_location.setText(INF.getLocation());
}
...
答案 0 :(得分:1)
Glide.with(ctx)
.load(information.get(position).getImage_id())
.placeholder(R.drawable.loading)
.into(holder.item_img);