Android Imageswitcher: periodically switch images?

I am using ImageSwitcher with TouchListener to modify images from an array. It works fine, but I want it to switch images every x seconds or so, so that I can add imageSwitcher.setImageResource(imageList[curIndex]); to him.

Any suggestions?

+4
source share
2 answers

Try it,

  imageSwitcher.postDelayed(new Runnable() { int i = 0; public void run() { imageSwitcher.setImageResource( i++ % 2 == 0 ? R.drawable.image1 : R.drawable.mage2); imageSwitcher.postDelayed(this, 1000); } }, 1000); 
+16
source

I think this is possible with TimerTask and Timer. try this code. I think this will help you.

  private Handler mHandler; private Runnable mUpdateResults; private Timer timerAnimate; private TimerTask timerTask; mHandler = new Handler(); mUpdateResults = new Runnable() { public void run() { AnimateandSlideShow(); } }; int delay = 0; int period = 15000; timerAnimate = new Timer(); timerTask = new TimerTask() { public void run() { mHandler.post(mUpdateResults); } }; timerAnimate.scheduleAtFixedRate(timerTask, delay, period); Public void AnimateandSlideShow() { imageSwitcher.setImageResource(imageList[curIndex]); ///Here You need To handle curIndex position. } 
+4
source

All Articles