android - Strange bug in listfragment -
i wanted study android sqlite created instant tagging application in user can tag photos , upload them network (google+, fb, twitter) problem have listfragment
in user can see tagging made, image elements in list stored on hidden folder , words stored in sqlite db.. problem while scrolling or down items switch randomly plus though have more 8 items them 8 first items shown repeatedly (i.e 1-8 instead of 9-12 see 1-4 again) problem might in adapter after sessions on sessions of debug fail find problem code adapter -
public class flowadapter extends baseadapter { private activity activity; private arraylist<hashmap<string, list<string>>> data; private static layoutinflater layoutinflater = null; public flowadapter(activity activitycontext, arraylist<hashmap<string, list<string>>> data) { this.activity = activitycontext; this.data = data; this.layoutinflater = (layoutinflater) activity .getsystemservice(context.layout_inflater_service); } public int getcount() { return data.size(); } public object getitem(int position) { return data.get(position); } public long getitemid(int position) { return position; } @override public view getview(int position, view convertview, viewgroup parent) { // method variables viewholder cacheview; hashmap<string, list<string>> photos = null; photos = data.get(position); imageview iv; flowlayout flow; arraylist<string> subjects = new arraylist<string>(); if (convertview == null) { cacheview = new viewholder(); convertview = layoutinflater.inflate(r.layout.list_item, null); flow = (flowlayout) convertview.findviewbyid(r.id.flow_tags);; // add tags flowlayout int size = photos.get(databasehandler.key_tags).size(); (int = 0; < size; i++) { string name = string.format("#%s", photos.get(databasehandler.key_tags).get(i)); bubble.getbubble(name, flow, subjects, activity, photos .get(databasehandler.key_thumbnailpath).get(1), false); } cacheview.image = (imageview)convertview.findviewbyid(r.id.list_image);//iv; cacheview.tags = flow; convertview.settag(cacheview); } cacheview = (viewholder) convertview.gettag(); cacheview.image.setimagebitmap(null); decodetask task = new decodetask(cacheview.image); task.execute(photos.get(databasehandler.key_thumbnailpath).get(1)); cacheview.image.settag(r.id.list_image, task); return convertview; } static class viewholder { static flowlayout tags; static imageview image; public static flowlayout getflowlayout() { return tags; } } }
the flow layout here - http://nishantvnair.wordpress.com/2010/09/28/flowlayout-in-android/ bubble layout here - http://nishantvnair.wordpress.com/2010/09/28/android-create-bubble-like-facebook/ use thread load images on background - large listview containing images in android help? =\ p.s know there apps [ , alot actually, best learning comes while writing code thats did =) ]
reason obvious !!! have static variables in viewholder
:
instead of:
static class viewholder { static flowlayout tags; static imageview image; public static flowlayout getflowlayout() { return tags; } }
it must be:
static class viewholder { flowlayout tags; imageview image; public flowlayout getflowlayout() { return tags; } }
more on static
variables available on internet, in short not instance variables changing value change every instance (although static
variable should accessed using class reference).
update:
you need cancel decodetask
if convertview
null tutorial says: large listview containing images in android
but keeping variables static
simple mistake , easy detect can detect mistake in 2+2 = 5
. saying removing static
modifier seems broke means else wrong code.
Comments
Post a Comment