如何使用Glide在适配器中加载图像数组?

问题描述 投票:-1回答:1

使用我当前的设置,它会导致RecyclerView滞后,因为我有很多资源图像。如何使用Glide加载图像数组而不是holder.item_img.setImageResource(INF.getImage_id());在我的ViewHolder中?

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());

}

...
android android-recyclerview adapter android-glide
1个回答
1
投票
Glide.with(ctx)
    .load(information.get(position).getImage_id()‌​)
    .placeholder(R.draw‌​able.loading)
    .into(h‌​older.item_img);
© www.soinside.com 2019 - 2024. All rights reserved.