How to implement showing several messages in a TextView field one by one with a required delay by clicking button only one time?
I tried this (look at the code below) and got such a result: three seconds go by and only "3" is shown in the end. Digits 1 and 2 aren't shown.
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.button.setOnClickListener {test()}
}
fun test() {
for (i in (1..3)){
binding.text1.text = "${i}"
Thread.sleep(1000L)
}
}
}