dimanche 29 décembre 2019

How to apply random list of numbers for selection from array to select image?

How to make list of random numbers and use it to set image from array?

val randomValues = List(15) { Random.nextInt(0, 5) }
var array = intArrayOf(R.drawable.cat1,R.drawable.cat2,R.drawable.cat3,R.drawable.cat4,R.drawable.cat5)
imageView.setImageResource(array[randomValues])

I'm getting Type mismatch on randomValues in imageView.setImageResource(array[randomValues]). Required: Int and Found: List >int< (I changed "<" signs directions because they becomes invisible here)




Aucun commentaire:

Enregistrer un commentaire