android - Animating lazy load of ArrayAdapter -
hello using animation arrayadapter. want animate thumbnail when loaded... every time thumbnail of list loaded, animation starts every items of array adapter. consequence, animation of each thumbnail started 5 times. have prevent starting animation when of items loaded?
public view getview(int position, view item, viewgroup parent){ viewholder holder; video video = mvideolist.get(position); if(item == null) { item = minflater.inflate(r.layout.adapter_recommended_videos, null); holder = new viewholder(); holder.title = (textview)item.findviewbyid(r.id.adapter_recommended_videos_textview); holder.thumb = (imageview)item.findviewbyid(r.id.adapter_recommended_videos_imageview); holder.title.settypeface( typeface.createfromasset(mcontext.getassets(), "roboto_medium.ttf")); item.settag(holder); } else { holder = (viewholder) item.gettag(); } holder.title.settext(video.gettitle()); imageview iv = holder.thumb; if (video.getthumb() != null) { if(!manimationflags.get(position)){ iv.startanimation(manimation); manimationflags.set(position, true); } holder.thumb.setimagebitmap(video.getthumb()); } else { holder.thumb.setimageresource(r.drawable.dummy_video_thumbnail); } return(item); } static class viewholder { textview title; imageview thumb; }
nevermind, solved myself, had instantiate new animation in each call of ´getview()´. here proper code:
public view getview(int position, view item, viewgroup parent){ viewholder holder; video video = mvideolist.get(position); if(item == null) { item = minflater.inflate(r.layout.adapter_recommended_videos, null); holder = new viewholder(); holder.title = (textview)item.findviewbyid(r.id.adapter_recommended_videos_textview); holder.thumb = (imageview)item.findviewbyid(r.id.adapter_recommended_videos_imageview); holder.title.settypeface( typeface.createfromasset(mcontext.getassets(), "roboto_medium.ttf")); item.settag(holder); } else { holder = (viewholder) item.gettag(); } holder.title.settext(video.gettitle()); imageview iv = holder.thumb; if (video.getthumb() != null) { if(!manimationflags.get(position)){ animation anim = animationutils.loadanimation(mcontext, android.r.anim.fade_in); iv.startanimation(anim); manimationflags.set(position, true); } holder.thumb.setimagebitmap(video.getthumb()); } else { holder.thumb.setimageresource(r.drawable.dummy_video_thumbnail); } return(item); }
Comments
Post a Comment