java - Setting image for imageview within listview yields odd results -
i have custom listview within list row layout has smartimageview (http://loopj.com/android-smart-image-view/)
i trying set each smartimageview on each row picture, below list adapter.
private class mylistadapter extends arrayadapter<listitem> { private arraylist<listitem> items; public mylistadapter(context context, int textviewresourceid, arraylist<listitem> items) { super(context, textviewresourceid, items); this.items = items; } @override public view getview(int position, view convertview, viewgroup parent) { view v = convertview; if (v == null) { layoutinflater vi = (layoutinflater)getsystemservice(context.layout_inflater_service); v = vi.inflate(r.layout.item_row_layout, null); } listitem o = items.get(position); if (o != null) { textview title = (textview) v.findviewbyid(r.id.ptitle); textview site = (textview) v.findviewbyid(r.id.site); textview price = (textview) v.findviewbyid(r.id.price); smartimageview img = (smartimageview) findviewbyid(r.id.smallimage); typeface font = typeface.createfromasset(getassets(), "asap-regular.ttf"); site.settypeface(font); title.settypeface(font); price.settypeface(font); if (title != null) { title.settext(o.gettitle()); } if (site != null) { site.settext("supplier name"); } if (price != null) { price.settext("£"+ string.valueof(o.getprice())); } if (img != null){ string url = o.getimage(); img.setimageurl(url); } } return v; } }
all other things set alright i.e title, price etc images not set correctly.
if there more 1 list item top item last items image, , rest has no image set. while if there 1 item in list not image set @ all.
if need more of code or information let me know!
you should try doig findviewbyid smartimageview calling
smartimageview img = (smartimageview) v.findviewbyid(r.id.smallimage);
this way, smartimageview in each view of list, otherwise, doesn't grab 1 specific row in listview.
Comments
Post a Comment