I am trying to make a slideshow of a few images while making an android app. I am using this code below
final int[] array = {R.drawable.cow_1, R.drawable.cow_2, R.drawable.cow_3, R.drawable.cow_4};
for (int i = 0; i < 4; i++){
final int finalI = i;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
animal_image.setImageResource(array[finalI]);
}
}, 4000);
}
The problem I am facing is that I am not getting the slideshow of images one-by-one instead the code is showing the last image after the first one directly. There's some problem with the code, please help me fix it.