timer - how to make slide show from List of images in android -
i have made android app,in getting arraylist of imageurls,i want make automated lsideshow in android using arraylis,i have tried below using thread gives me arrayindexoputofbounds exception,it goes second image abd gives exception,please me save me,my code below:
resultarray = new arraylist<string>(); iv_paly.setonclicklistener(new onclicklistener()){ @override onclick(){ imageloader.displayimage(resultarray.get(1), proimage, options); proimage.postdelayed(swapimage, 3000); } mediaplayer introsound, bellsound; runnable swapimage = new runnable() { @override public void run() { (int = 0; <= resultarray.size(); i++) { imageloader.displayimage(resultarray.get(i), proimage, options); } } }; }
try code
package com.example.imagegal; import android.os.bundle; import android.app.activity; import android.content.context; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.viewgroup; import android.view.window; import android.view.animation.animationutils; import android.widget.adapterview; import android.widget.baseadapter; import android.widget.gallery; import android.widget.imageswitcher; import android.widget.imageview; import android.widget.viewswitcher; import android.widget.gallery.layoutparams; import android.support.v4.app.navutils; public class mainactivity extends activity implements adapterview.onitemselectedlistener, viewswitcher.viewfactory { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); setcontentview(r.layout.activity_main); mswitcher = (imageswitcher) findviewbyid(r.id.switcher); mswitcher.setfactory(this); mswitcher.setinanimation(animationutils.loadanimation(this, android.r.anim.slide_out_right)); mswitcher.setoutanimation(animationutils.loadanimation(this, android.r.anim.slide_in_left)); gallery g = (gallery) findviewbyid(r.id.gallery); g.setadapter(new imageadapter(this)); g.setonitemselectedlistener(this); } public void onitemselected(adapterview<?> parent, view v, int position, long id) { mswitcher.setimageresource(mimageids[position]); } public void onnothingselected(adapterview<?> parent) { } public view makeview() { imageview = new imageview(this); i.setbackgroundcolor(0xff000000); i.setscaletype(imageview.scaletype.fit_center); i.setlayoutparams(new imageswitcher.layoutparams(layoutparams.match_parent, layoutparams.match_parent)); return i; } private imageswitcher mswitcher; public class imageadapter extends baseadapter { public imageadapter(context c) { mcontext = c; } public int getcount() { return mthumbids.length; } public object getitem(int position) { return position; } public long getitemid(int position) { return position; } public view getview(int position, view convertview, viewgroup parent) { imageview = new imageview(mcontext); i.setimageresource(mthumbids[position]); i.setadjustviewbounds(true); i.setlayoutparams(new gallery.layoutparams( layoutparams.wrap_content, layoutparams.wrap_content)); i.setbackgroundresource(r.drawable.background); return i; } private context mcontext; } private integer[] mthumbids = { r.drawable.a, r.drawable.b, r.drawable.c, r.drawable.d}; private integer[] mimageids = { r.drawable.a, r.drawable.b, r.drawable.c, r.drawable.d}; }
xml file
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <imageswitcher android:id="@+id/switcher" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignparenttop="true" android:layout_alignparentleft="true" /> <gallery android:id="@+id/gallery" android:background="#55000000" android:layout_width="match_parent" android:layout_height="60dp" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:gravity="center_vertical" android:spacing="16dp" /> </relativelayout>
Comments
Post a Comment