I am trying load image one by one from sdcard folder images and using handler after few seconds they automatically change but does not change other image is showing only one image
Here I put my handler code for get and set image on create activity
HomeActivity.java
final Handler imagehandler = new Handler();
Runnable runnable;
runnable = new Runnable()
{
int i=0;
@SuppressLint("SdCardPath")
public void run()
{ // slider image run
File dir = new File("/mnt/sdcard/images/");
File file[]=dir.listFiles();
for (int i=0;i<file.length;i++)
{
Drawable d = (Drawable) Drawable.createFromPath(file[i].toString());
imageslider.setImageDrawable(d);
imagehandler.postDelayed(this, 4000);
// for interval
}
};
imagehandler.postDelayed(runnable,10);
}
remove for loop from Runnable before this will show always last image in imageView . instead of for loop use a counter for showing images like :