Recyclerview Adapter and Glide - same image every 4-5 rows

前端 未结 5 1386
北荒
北荒 2020-12-02 13:01

I have this problem - just for testing purposes I added ParseFile to one of ParseObject from received list. Instead of showing it only in that row

5条回答
  •  忘掉有多难
    2020-12-02 13:36

    In RecyclerView each row is recycled with new data. In your code you are setting ImageView only when it's not null and otherwise doing nothing. In this case when it's not null ImageView will show old image since you didn't override for the current object. You can fix this by adding else condition and setting ImageView to null/blank anything.

    @Override 
        public void onBindViewHolder(ViewHolder holder, int position) {
            if(parseList.get(position).get("logo") != null){
                ParseFile image = (ParseFile) parseList.get(position).get("logo");
                String url = image.getUrl();
                Glide.with(context) 
                        .load(url)
                        .placeholder(R.drawable.piwo_48)
                        .transform(new CircleTransform(context)) 
                        .into(holder.imageView);
    
    
            } 
            else{
                holder.imageView.setImageDrawable(null);
            }
        } 
    

提交回复
热议问题