Question

I am using an ImageSwitcher with a TouchListener to change images from an array. Its working fine but i want it to switch images every x seconds or so, so that I can add imageSwitcher.setImageResource(imageList[curIndex]); to it.

Any suggestions?

Était-ce utile?

La solution

Try this,

 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);

Autres conseils

I think it is possible via TimerTask and Timer. please Try this code. I think It 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.
                }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top