3

I'm using Picasso in onBindViewHolder but when scrolling up or down it reload same images urls from internet this make the list so bad and slow

so i want when it first load save the scroll state for images and do not load it again '

how i can do that?

onBindViewHolder Method :

@Override
    public void onBindViewHolder(MyCustomAdapter.CustomViewHolder holder, int position) {

            Dishes di = dish.get(position);
            //Download image using picasso library
            Picasso.with(mContext).load(di.getDishImageUrl())
                    .error(R.drawable.ic_error)
                    .placeholder(R.drawable.fav_btn)
                    .into(holder.imageView);

            //Setting text view title
            holder.textView.setText(Html.fromHtml(di.getDishName()));

            View.OnClickListener clickListener = new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                            CustomViewHolder holder = (CustomViewHolder) view.getTag();
                            int position = holder.getPosition();

                            Dishes di = dish.get(position);
                            Toast.makeText(mContext, di.getDishName(), Toast.LENGTH_SHORT).show();
                    }
            };

            //Handle click event on both title and image click
            holder.textView.setOnClickListener(clickListener);
            holder.imageView.setOnClickListener(clickListener);

            holder.textView.setTag(dish.get(position));
            holder.imageView.setTag(dish.get(position));

    }
  • 1
    Are you sure that `Picasso` downloads images from internet constantly? By default it caches images into memory and reuses them. There is nothing wrong with your `onBindViewHolder` method. – eleven Feb 07 '16 at 19:14
  • Possible duplicate of https://stackoverflow.com/questions/27743339/strange-behaviour-of-images-in-recyclerview – mahmoud moustafa Feb 07 '16 at 19:17
  • @Fox in socks yes it works it caches but when get back to top list scroll i found that default image icon is loaded first then loading the URL image , i have set default image as "star.png" then when loading all images successfully star disappear this is right but when get back again i found that star.png is shown and after 1 second the right image is shown – Hashoma El-Nemr Feb 07 '16 at 20:18

0 Answers0