android - Bad data interpretation when scrolling of Listview -
i wrote code custom listview. in listview have textview hidden circumstances. works when scroll view down. however, when scroll view textvie hidden. know has setting tags elements. tried examples different sides, however, textview's disappear :( custom arrayadapter code:
class wallpaperslistadapter extends arrayadapter<wallpaper> { private list<wallpaper> wallpaperscontainer; private imageloader imageloader; private displayimageoptions imageloaderoptions; public wallpaperslistadapter(context context, list<wallpaper> wallpaperscontainer) { super(context, r.layout.wallpaper_view, wallpaperscontainer); this.wallpaperscontainer = wallpaperscontainer; setimageloaderoptions(); } private void setimageloaderoptions() { imageloaderoptions = new displayimageoptions.builder() //.showimageonloading(r.drawable.place_holder) //.showimageforemptyuri(r.drawable.question) //.showimageonfail(r.drawable.big_problem) .imagescaletype(imagescaletype.exactly) .cacheinmemory(true) .cacheondisk(true) .build(); imageloader = imageloader.getinstance(); } @override public int getcount() { return wallpaperscontainer.size(); } @override public wallpaper getitem(int position) { wallpaper wallpaper = wallpaperscontainer.get(position); return wallpaper; } @override public long getitemid(int position) { return position; } @override public view getview(int position, view convertview, viewgroup parent) { view itemview = convertview; wallpaperviewholder currentwallpaperviewholder; // have view if (convertview == null) { // don't have view create 1 inflating layout itemview = layoutinflater.from(getcontext()).inflate(r.layout.wallpaper_view, parent, false); itemview.getlayoutparams().height = parent.findviewbyid(r.id.wallpapers_list_view).getmeasuredheight(); currentwallpaperviewholder = getwallpaperviewholder(itemview); // set tag view current person view holder itemview.settag(currentwallpaperviewholder); itemview.settag(r.id.wallpaper_author, currentwallpaperviewholder.wallpaperauthor); itemview.settag(r.id.wallpaper_site, currentwallpaperviewholder.wallpapersite); } else { // have view tagged view currentwallpaperviewholder = (wallpaperviewholder) itemview.gettag(); } currentwallpaperviewholder.wallpaperauthor.settag(position); currentwallpaperviewholder.wallpapersite.settag(position); setwallpaperviewcontent(wallpaperscontainer.get(position), currentwallpaperviewholder); return itemview; } private void setwallpaperviewcontent(wallpaper wallpaper, wallpaperviewholder wallpaperviewholder) { string authorname = wallpaper.getauthorname(); string authorsite = wallpaper.getauthorsite(); if (authorname == null) { wallpaperviewholder.wallpaperauthor.setvisibility(view.gone); } else { wallpaperviewholder.wallpaperauthor.settext(getcontext().getstring(r.string.wallpaper_author_name) + " " + authorname); } if (authorsite == null) { wallpaperviewholder.wallpapersite.setvisibility(view.gone); } else { wallpaperviewholder.wallpapersite.settext(getcontext().getstring(r.string.wallpaper_author_site) + " " + authorsite); } wallpaperviewholder.wallpaperdateforuse.settext(wallpaper.getdateforuse()); imageloader.displayimage( wallpaper.gethdurl()//the drawable , wallpaperviewholder.imageviewwallpaper//the image view , imageloaderoptions);//the display options } private wallpaperviewholder getwallpaperviewholder(view itemview) { wallpaperviewholder wallpaperviewholder = new wallpaperviewholder(); wallpaperviewholder.wallpaperdateforuse = (textview) itemview.findviewbyid(r.id.wallpaper_date_for_use); wallpaperviewholder.imageviewwallpaper = (imageview) itemview.findviewbyid(r.id.wallpaper_image); wallpaperviewholder.wallpaperauthor = (textview) itemview.findviewbyid(r.id.wallpaper_author); wallpaperviewholder.wallpapersite = (textview) itemview.findviewbyid(r.id.wallpaper_site); wallpaperviewholder.setwallpaperbtn = (button) itemview.findviewbyid(r.id.wallpaper_set); return wallpaperviewholder; } private static class wallpaperviewholder { imageview imageviewwallpaper; textview wallpaperdateforuse; textview wallpaperauthor; textview wallpapersite; button setwallpaperbtn; } }
in else cases have change visibility textviews other wise don't visible.
if (authorname == null) { wallpaperviewholder.wallpaperauthor.setvisibility(view.gone); } else { wallpaperviewholder.wallpapersite.setvisibility(view.visible); wallpaperviewholder.wallpaperauthor.settext(getcontext().getstring(r.string.wa llpaper_author_name) + " " + authorname); }
hope helps you.
Comments
Post a Comment