Issue
Can you get a resource from a string like this in Kotlin?
val diceImage: ImageView = findViewById(R.id.imageView)
val diceRoll = (1..6).random()
diceImage.setImageResource("R.drawable.dice_${i}")
Solution
You can use the getIdentifier method:
val id = resources.getIdentifier("resourceName", "drawable", packageName)
imageView.setImageResource(id)
Answered By - Gabriele Mariotti
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.