Android Imageswitcher: switch images periodically?

喜你入骨 提交于 2019-12-03 16:55:26

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

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.
                }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!