mercredi 20 novembre 2019

Using android kotlin - problem with random number display + delay

I am using kotlin in Android Studio. I am writing a simple program to display a series of random numbers with a delay of 1 second between each one. RandNumText is the name of the on screebn box. I have tried the following :-

enter code herei=1 enter code herewhile (i<10) { enter code hereRandNumText.text = ((0..9).random()).toString() enter code herefor (j in 0 until 50000) { enter code here} enter code herei++ enter code here}


enter code herei=1 enter code herewhile (i<10) { enter code hereRandNumText.text = ((0..9).random()).toString() enter code here Thread.sleep(1000) // wait for 1 second enter code herei++ enter code here}


enter code herei = 1 enter code hereval handler = Handler() enter code herewhile (i<10) { enter code herehandler.postDelayed({ enter code hereRandNumText.text = ((0 until 10).random()).toString() enter code here}, 1000) enter code herei++

enter code here}

Each time just one number appears on screen. What am I doing wrong? Your assistance would be appreciated. Thanks.




Aucun commentaire:

Enregistrer un commentaire