Downloading Image in Recyclerview

白昼怎懂夜的黑 提交于 2020-01-02 20:12:02

问题


I have a recycler view which has an Imageview in the Viewholder. The Image is downloaded via AsyncTask in the onBindViewHolder in the adapter.

The problem is when I scroll down or up, the onBindViewHolder is called for recycling the view holder and the Images are downloaded again and again. Now I understand that this is how Recyclerview is supposed to work. So can anyone tell me if anything can be done to avoid downloading the Images more than once. Or will it be better to move back to ListView.


回答1:


Use Picasso and cache the image. And I guess Picasso Cache the image by default.

Example

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);



回答2:


hold List of Bitmap or Drawable in adapter's field and get image from that list. You can take image's index by getLayoutPosition() method in onBindViewHolder



来源:https://stackoverflow.com/questions/34692872/downloading-image-in-recyclerview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!