There is a RecyclerView with publications (there is an ImageView in the view of these publications). For example, I downloaded 100 publications from the Internet and for each, using Picasso, the library loads pictures into ImageView.

Picasso.with(context).load(url).placeholder(placeholderImage).error(errorImage).into(ImageView); 

So the problem is that in the first 7-10 publications the images are loaded and the rest are also placeholderImage. There is a catch that this is due to the fact that if the not yet loaded ImageView goes to the RecyclerView cache, then it still remains a placeholderImage. But I do not know because of what exactly and how to solve?

Vota adapter code:

 public class RecAdapter extends RecyclerView.Adapter<RecAdapter.ViewHolder> { private ArrayList<Data_Publication> data; private LayoutInflater inflater; private Context context; private Callback callback; public RecAdapter(Context context , ArrayList<Data_Publication> data_list , Callback callback){ this.context = context; this.data = data_list; this.inflater = LayoutInflater.from(context); this.callback = callback; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = inflater.inflate(R.layout.publication, parent , false); return new ViewHolder(view); } @Override public void onBindViewHolder(ViewHolder holder, int position) { Data_Publication pub = data.get(position); holder.setName(pub.getProduct_name()); holder.setPrice(pub.getProduct_price()); holder.setLocation(pub.getProduct_locaton()); holder.setClicker(pub.getProduct_id() , pub.getProduct_name()); holder.loadImage(pub.getPhotoStroge().concat(pub.getImage_url())); } @Override public int getItemCount() { return data.size(); } public class ViewHolder extends RecyclerView.ViewHolder{ final private TextView name; final private TextView price; final private TextView location; final private ImageView image; final private LinearLayout content; final private LinearLayout main; private ViewHolder(View view) { super(view); this.name = (TextView) view.findViewById(R.id.pub_name); this.price = (TextView) view.findViewById(R.id.pub_price); this.location = (TextView) view.findViewById(R.id.pub_location); this.image = (ImageView) view.findViewById(R.id.pub_image); this.content = (LinearLayout) view.findViewById(R.id.pub_content); this.main = (LinearLayout) view.findViewById(R.id.pub_main); } public void setName(String name) { this.name.setText(name); } public void setPrice(String price) { this.price.setText(price); } public void setLocation(String location){ this.location.setText(location); } public void loadImage(String url){ Picasso.with(context).load(url).placeholder(R.drawable.placeholder).error(R.drawable.error_ph).into(this.image); } public void setClicker(final String id , final String name){ final Animation anim = AnimationUtils.loadAnimation(context, R.anim.move_left); content.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { main.startAnimation(anim); callback.operation(id , name); } }); } } } 
  • Use Glide instead of Picasso. Do the loading and do not load the whole thing - Flippy
  • And you, probably, these same 7-10 fit on the screen at the same time? Perhaps you are not using Picasso there. Show the method code where everything happens. - woesss
  • @woesss Yes, that's right. Adapter code added please take a look - Fariz Mamedow
  • @Flippy did not hear about glide. Will it save traffic and speed? and whether ekzampla good? - Fariz Mamedow
  • @Flippy I understood how to load but there is nothing written about loading - Fariz Mamedow

1 answer 1

Edited here, so there may be errors

If the problem is only in downloading the picture, then try this.

 public class RecAdapter extends RecyclerView.Adapter<RecAdapter.ViewHolder> { private ArrayList<Data_Publication> data; private LayoutInflater inflater; private Context context; private Callback callback; public RecAdapter(Context context , ArrayList<Data_Publication> data_list , Callback callback){ this.context = context; this.data = data_list; this.inflater = LayoutInflater.from(context); this.callback = callback; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { сontext = parent.getContext(); //Подставляем context View view = inflater.inflate(R.layout.publication, parent , false); return new ViewHolder(view); } @Override public void onBindViewHolder(ViewHolder holder, int position) { Data_Publication pub = data.get(position); holder.setName(pub.getProduct_name()); holder.setPrice(pub.getProduct_price()); holder.setLocation(pub.getProduct_locaton()); holder.setClicker(pub.getProduct_id() , pub.getProduct_name()); //holder.loadImage(pub.getPhotoStroge().concat(pub.getImage_url())); Picasso.with(context) .load(pub.getImage_url()) //Всякие ваши плюшки .into(holder.image); } @Override public int getItemCount() { return data.size(); } public class ViewHolder extends RecyclerView.ViewHolder{ final private TextView name; final private TextView price; final private TextView location; final private ImageView image; final private LinearLayout content; final private LinearLayout main; private ViewHolder(View view) { super(view); this.name = (TextView) view.findViewById(R.id.pub_name); this.price = (TextView) view.findViewById(R.id.pub_price); this.location = (TextView) view.findViewById(R.id.pub_location); //Не уверен, нужен ли здесь this // но я делаю так image = (ImageView) view.findViewById(R.id.pub_image); this.content = (LinearLayout) view.findViewById(R.id.pub_content); this.main = (LinearLayout) view.findViewById(R.id.pub_main); } public void setName(String name) { this.name.setText(name); } public void setPrice(String price) { this.price.setText(price); } public void setLocation(String location){ this.location.setText(location); } // Обработку тапа тоже бы перенес в onBindViewHolder! public void setClicker(final String id , final String name){ final Animation anim = AnimationUtils.loadAnimation(context, R.anim.move_left); content.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { main.startAnimation(anim); callback.operation(id , name); } }); } } } 
  • and what has changed here? Just dropped the download from the viewholder in onBind? - Fariz Mamedow
  • Have you tried? I recommend to review the entire code! - dev.android
  • No, I have not tried it, but do you think this will help? - Fariz Mamedow