Android ViewFlipper animating only the first URL image -
i have android activity viewflipper. picks images url , displays in layout. supposed animate though images. however, animates first url image , keeps repeating. not display other images. below code:
public class dynamicviewflipper extends activity {
/** * list of image url populate viewflipper */ private list<string> imageurls = arrays.aslist(new string[] { "http://example.com/image1.jpg", "http://example.com/image2.jpg", "http://example.com/image3.jpg", "http://example.com/image4.jpg"}); private int index = 0; private textview mtextview; private viewflipper mviewflipper; private button mnextbutton; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_view_flipper); mtextview = (textview) findviewbyid(r.id.title); mviewflipper = (viewflipper) findviewbyid(r.id.viewflipper); imageview image = new imageview(getapplicationcontext()); urlimageviewhelper.seturldrawable(image, getnextimage(), r.drawable.loading); mtextview.settext("showing: " + index); mviewflipper.addview(image); mviewflipper.shownext(); mviewflipper.setautostart(true); mviewflipper.setflipinterval(2000); mviewflipper.startflipping(); mviewflipper.setinanimation(animationutils.loadanimation(getapplicationcontext(), android.r.anim.slide_in_left)); mviewflipper.setoutanimation(animationutils.loadanimation(getapplicationcontext(), android.r.anim.slide_out_right)); } protected string getnextimage() { if (index == imageurls.size()) index = 0; return imageurls.get(index++); }
}
you should have that:
for(string url: imageurls){ imageview image = new imageview(getapplicationcontext()); urlimageviewhelper.seturldrawable(image, url,r.drawable.loading); mviewflipper.addview(image); } mviewflipper.setautostart(true); mviewflipper.setflipinterval(2000); mviewflipper.startflipping();
Comments
Post a Comment