Home > Enterprise >  Kotlin a text for each drawable
Kotlin a text for each drawable

Time:06-08

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

My app

CodePudding user response:

You could create a function that maps drawable ids to string ids:

@StringRes
fun getTextId(@DrawableRes drawableId: Int): Int =
    when (drawableId) {
        R.drawable.image_one -> R.string.text_one
        R.drawable.image_two -> R.string.text_two
        R.drawable.image_three -> R.string.text_three
        ...
        else -> error("unexpected drawable id")
    }

The best solution will depend on exactly how you are choosing/displaying your random images.

  • Related