The code throws an error!

Report a typo

Steph is trying to implement a function to be called whenever a button is clicked. She uses another thread to do a few calculations, then updates the UI for her app. However, the code is not working. Help her and identify the problem.

button.setOnClickListener {
    thread {
        for (i in 0..5) {
            Thread.sleep(100) // pretend doing some calculations
            counterTextView.text = i.toString() // update the UI
        }
    }
}
Select one option from the list
___

Create a free account to access the full topic