I have this screen, I need appropriate text for each r.drawable that is seen in random mode, in each imageview, I wrote the app in KOTLIN and I'm almost done, I just need this text resource explaining the displayed image , to each image its text, can you help me? thank you
I don't know how to create a text that changes according to the image
private lateinit var listId: List<Int>
private fun pickNumber (){
val (id1, id2, id3) = listId.shuffled()
binding.imageView.setImageResource(id1)
binding.imageView2.setImageResource(id2)
binding.imageView3.setImageResource(id3)
private fun initializeList() {
listId = listOf(
R.drawable.r02 ,
R.drawable.w02s,
R.drawable.ror,
R.drawable.rands,
R.drawable.rups,
R.drawable.rles,
R.drawable.rsw)
CodePudding user response:
The easiest way for you to link each text resource to appropriate image resourse is to change type of listId
variable from List<Int>
to Map<Int, Int>
. Now it will contain pairs of image resources and text resources. Also you should change listOf(...)
method to mapOf(R.drawable.desired_drawable to R.string.desired_text, ...)
and listId.shuffled()
to listId.toList().shuffled()
. After this you can just operate with gained pairs of values to set them to corresponding views.