Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - How to stop images reloading in Recyclerview when scrolling

I was creating an app for loading images from internet in cards. I am using Recyclerview for listing purpose. For downloading images, I have tried Picasso, universal-image-downloader and other custom methods but everywhere I have this problem:

Whenever I scroll down and up the images in imageview are getting reloaded. I have even kept a condition to check if the imageview contains an image but that also doesn't seem to work or my code may be faulty. But I am not able to find a solution to this problem. Below I have attached the 'onBindViewHolder' function of my code which I think is the problematic part. Here images is a string arraylist containing image urls.

public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {            
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.default_card, parent, false);

        ViewHolder viewHolder;
        viewHolder = new ViewHolder(view);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {            
        String url = images.get(position);

        if (holder.imgView.getDrawable() != null) {
            //Do Nothing
        } else {                
            ImageLoader.getInstance().displayImage(url, holder.imgView);               
        }
    }
like image 367
skdhfgeq2134 Avatar asked May 14 '15 11:05

skdhfgeq2134


People also ask

How do I stop refreshing RecyclerView data scroll to top position android?

Make a setDataList method in your adapter class. And set your updated list to adapter list. And then every time of calling API set that list to setDataList and call adapter. notifyDataSetChanged() method of your adapter class.

How do I make my RecyclerView scroll smooth?

Use the setHasFixedsize method If the height of our RecyclerView items is fixed then we should use the setHasFixedsize method in our XML of our card item. This will fix the height of our RecyclerView item and prevent it from increasing or decreasing the size of our Card Layout.

Is RecyclerView scrollable Android?

More about RecyclerView could be found at RecyclerView in Android with Example. RecyclerView lets the users scroll up and down and left and right by setting appropriate orientation via attributes.

How do I disable multitouch RecyclerView?

To disable multi touch in recyclerview, you can use android:splitMotionEvents="false" in your recyclerview tag in layout file. By that attribute, you will not receive multi touch in recyclerview.


1 Answers

You can use this to solve your issue.

mRecyclerView.getRecycledViewPool().setMaxRecycledViews(0, 0);
like image 200
Ashutosh Avatar answered Oct 20 '22 11:10

Ashutosh