java - HorizontalGridView/ RecyclerView scroll position resets once Picasso image loads -
i have horizontalgridview , working well, loading images picasso , whenever image loads, horizontalgridview snaps first item/starting scroll position. have map fragment on activity , notice when map interacted with, horizontalgridview displays the same behavior. below adapter code. please help, have been stuck on 1 couple of days now...
public class gridelementadapter extends recyclerview.adapter<gridelementadapter.simpleviewholder>{ private context context; private deal[] mdeals; public gridelementadapter(context context, deal[] deals){ this.context = context; this.mdeals = deals; } public static class simpleviewholder extends recyclerview.viewholder { public final imageview dealimage; public final textview dealtitle; public final textview dealsubtitle; public final textview dealprice; public final textview dealtime; public final textview dealdays; public simpleviewholder(view view) { super(view); dealimage = (imageview) view.findviewbyid(r.id.griddealimageview); dealtitle = (textview) view.findviewbyid(r.id.gridtitlelabel); dealsubtitle = (textview) view.findviewbyid(r.id.gridsubtitlelabel); dealprice = (textview) view.findviewbyid(r.id.gridpricelabel); dealtime = (textview) view.findviewbyid(r.id.gridavailabletimelabel); dealdays = (textview) view.findviewbyid(r.id.gridavailabledayslabel); } } @override public simpleviewholder oncreateviewholder(viewgroup parent, int viewtype) { final view view = layoutinflater.from(this.context).inflate(r.layout.deal_grid_item, parent, false); return new simpleviewholder(view); } @override public void onbindviewholder(simpleviewholder holder, final int position) { string dealimageurl = "http://api.cheapeat.com.au/deals/" + mdeals[position].getphotoid() + "/photo"; context context = holder.dealimage.getcontext(); picasso.with(context).load(dealimageurl).placeholder(r.drawable.deal_image_placeholder).into(holder.dealimage); holder.dealtitle.settext(mdeals[position].getname()); holder.dealprice.settext(mdeals[position].getpricedata()); holder.dealsubtitle.settext(mdeals[position].getdescription()); holder.dealtime.settext(mdeals[position].getavailabilitytime()); holder.dealdays.settext(mdeals[position].getformattedavailabledays(mdeals[position].getavailabilityday())); } @override public long getitemid(int position) { return position; } @override public int getitemcount() { return this.mdeals.length; }
}
so managed solve one. turns out hadn't set layoutmanager
horizontalgridview
. specifically, in activity set adapter:
// had horizontalgridview = (horizontalgridview) findviewbyid(r.id.gridview); gridelementadapter adapter = newgridelementadapter(venueprofileactivity.this, mdeals); horizontalgridview.setadapter(adapter); // needed added horizontalgridview.layoutmanager layoutmanager = new linearlayoutmanager(venueprofileactivity.this, linearlayoutmanager.horizontal, false); horizontalgridview.setlayoutmanager(layoutmanager); horizontalgridview.sethasfixedsize(true);
hopefully saves headaches, i've seen question floating around no correct solution yet.
Comments
Post a Comment