android - TextViews recycle their positions and title when scrolling, Glide Gallery -
i trying use glide image library load images in gridview using reccycler view. however, wanted have title textview beneath each image.
i have set custom layout , tried load textview in onbindviewholder. works on scrolling, positions recycled, , textviews titles changed, making mess of it.
@override public void onbindviewholder(myviewholder holder, int position) { image image = images.get(position); // // setup glide request without into() method // drawablerequestbuilder<string> thumbnailrequest = glide // .with(mcontext) // .load(image.getmedium()); // pass request a parameter thumbnail request glide.with(mcontext).load(image.getmedium()) .thumbnail(0.3f) .crossfade() .diskcachestrategy(diskcachestrategy.all) .into(holder.thumbnail); titletext.settext(image.getname()); }
how fix dear developers?
i think problem titletext not stored in viewholder.
save inside holder object , use:
holder.titletext.settext(image.getname());
this change textview accordingly holder changes. else mess holders recycled.
something like:
class myviewholder extends recyclerview.viewholder{ textview titletext; imageview thumbnail; . . . @override public void onbindviewholder(myviewholder holder, int position) { image image = images.get(position); glide.with(mcontext).load(image.getmedium()) .thumbnail(0.3f) .crossfade() .diskcachestrategy(diskcachestrategy.all) .into(holder.thumbnail); holder.titletext.settext(image.getname()); } }
Comments
Post a Comment