如何使用 Glide 在适配器中加载图像数组?
How to use Glide to load an array of images in an Adapter?
在我当前的设置下,它会导致 RecyclerView 延迟,因为我有很多资源图像。如何使用 Glide 在我的 ViewHolder 中加载图像数组而不是 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());
}
...
Glide.with(ctx)
.load(information.get(position).getImage_id())
.placeholder(R.drawable.loading)
.into(holder.item_img);
在我当前的设置下,它会导致 RecyclerView 延迟,因为我有很多资源图像。如何使用 Glide 在我的 ViewHolder 中加载图像数组而不是 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());
}
...
Glide.with(ctx)
.load(information.get(position).getImage_id())
.placeholder(R.drawable.loading)
.into(holder.item_img);