UI does not update in repeat (Android-Kotlin)

Viewed 10

I have code to update the screen with a new image every 3 seconds but it only updates at the end of the loop and only with the last image

my code essentially

button.setOnClickListener {
            repeat(5){
                Thread.sleep(3000)
                findViewById<ImageView>(R.id.imageView).setImageResource(getDrawableResource(it))
            }
        }

I did not think it necessary to provide the rest of my code because it works, I only introduced the repeat because I wanted to see it loop through the images and found it does not work as expected.

0 Answers
Related