I am using ImageDownloader class to get images from server and getting these images links using an ArrayList. After downloading the Image I am setting the Image
Set up your ImageView like this:
You can Use TimerTask to achieve this.
// Declaration and Initialization :
List mImageUrl = new ArrayList();
private ImageLoader mImageLoader = new ImageLoader(MainActivity.this);
Timer timer = new Timer(); // changed
int i = 0;
// Put this code in your onCreate :
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (i < mImageUrl.size()) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
mImageLoader.DisplayImage(mImageUrl.get(i), img);
i++;
}
});
} else {
i = 0;
}
}
}, 0, 2000);
The timer task will start in 0 seconds and it will change the background every 2 seconds. You can change this as like as you want. Its working fine. I have tested.
You can read more about the timertask here.
You can also cancel the timer with the help of timer.cancel() HIH.