Question

Currently my code displays a single image from a file path (in SDCard). This is in onCreate() method for now:

 ImageView imgView01 = (ImageView) findViewById(R.id.imageView1);  
 File dir = new File("/sdcard/WallpapersHD/");
 File file[]=dir.listFiles();
 for (int i=0;i<file.length;i++) {
      Drawable d = (Drawable) Drawable.createFromPath(file[i].toString());
      imgView01.setImageDrawable(d);
      }

I want to display all the images in that particular folder one after the other using a time delay of say 5 seconds. If I can create a new drawable for each image in the folder, How do I do it? and how do I change the image in ImageView to set that drawable's path?

Was it helpful?

Solution

You could use an ImageSwitcher for convenience, and then do:

    imageSwitcher.postDelayed(
            new Runnable() {
                @Override
                public void run() {
                    i++;
                    imageSwitcher.setImageURI(Uri.fromFile(file[i]));
                    imageSwitcher.postDelayed(this, millisBetweenImages);
                }
            },
            millisBetweenImages);

it also has a setImageDrawable-method if you want to keep your images as Drawables.

OTHER TIPS

Create a drawable for each image, and then keep changing the image in your ImageView, perhaps in a Handler or TimerTask.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top