0

I want to show multiple images in my imageView I want to do this by using a for loop, but my image view only shows the last image.

I have tried Thread.sleep and sleep functions too but they didn't work

for(int i=0;i<=3;i++){
                try {

                    pic = picText.getText().toString();
                    String photoPath = "sdcard/Pictures/" + pic + i + ".jpg";
                    imageView.setImageBitmap(BitmapFactory.decodeFile(photoPath));
                    sleep(1000);
                } catch (Exception ex) {

                }}

I expect to get all the images one after other, the delay is given in sleep() function.

Pavel Smirnov
  • 4,611
  • 3
  • 18
  • 28
  • 4
    Possible duplicate of [Show multiple images in a imageView one after another with left to right flip effect repeatedly](https://stackoverflow.com/questions/27167866/show-multiple-images-in-a-imageview-one-after-another-with-left-to-right-flip-ef) – namu Apr 09 '19 at 17:03

2 Answers2

0

Use Thread.sleep(1000) which pause the execution of current thread for specified time in milliseconds.

Goutham
  • 307
  • 2
  • 11
0

Get all the imagepath in array or ArrayList and then use a handler and timertask

Timer t; Handler handler; Runnable update; handler = new Handler(); update = new Runnable() { @Override public void run() {

            //load photo
        }
    };
    t = new Timer();
           t.schedule(new TimerTask() {
               @Override
               public void run() {
                   handler.post(update);
               }
           }, 0, 5000);
Note if its showing last image, redirect counter to 1st image. Hope this helps