android - RecyclerView and Picasso images disappear after scrolling -
i didn't find answer here, here , here.
i have activity shows list of posts (with or without images). when scroll down , scroll or refresh list using swiperefreshlayout
of images may disapper. use recyclerview
show list of posts , picasso
load images. here adapter binding:
@override public void onbindviewholder(itemviewholder holder, int position) { // <...> if (item.getphoto() != null) { picasso.with(context) .load(item.getphoto()) .into(holder.mpostphoto); } else { holder.mpostphoto.setimagedrawable(null); holder.mpostphoto.setvisibility(view.gone); } }
i send http request posts , when have new data call postsadapter
:
public void addall(list<postresponse> items) { this.items.clear(); this.items.addall(items); notifydatasetchanged(); }
in mainactivity:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); // <...> mpostadapter = new postadapter(); mposts.setlayoutmanager(new linearlayoutmanager(mainactivity.this)); mposts.setadapter(mpostadapter); mpostsswiperefresh.setonrefreshlistener(new swiperefreshlayout.onrefreshlistener() { @override public void onrefresh() { updateposts(); } }); updateposts(); } private void updateposts() { new api(this).getposts(new getpostscallback(this) { @override public void onsuccess(final paging<postresponse> paging) { runonuithread(new runnable() { @override public void run() { mpostadapter.addall(paging.getdata()); mpostsswiperefresh.setrefreshing(false); } }); } }); }
i find it's pretty basic, don't understand why images disappear time after time. list not long , images resized before upload server, shouldn't use memory. , worst, when disappear, don't reload. may reload after scroll down , up...
- please explain me why happens.
- how can fix problem?
thanks!
so, apparently recyclerview
recycling items list , reason couldn't reload images after that. question "why?"... maybe because did wrong, not sure. helped me:
recyclerview.getrecycledviewpool().setmaxrecycledviews(0, 0);
basically turning off items recycling. works me because don't render huge lists of items.
Comments
Post a Comment