Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Imageswitcher: switch images periodically?

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?

like image 404
Akash Malhotra Avatar asked Dec 01 '22 05:12

Akash Malhotra


1 Answers

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);
like image 84
Andro Selva Avatar answered Dec 04 '22 12:12

Andro Selva