Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is that possible to use variables when calling an string from resources?

I know it’s a silly quastion but when calling a string from resources(R.string.xxx), are there any ways to call an string name using variables?(for example R.string.$text).

Like:

fun mapCreator(unique:String,map:MutableMap<String,Any>,insideMap:MutableMap<Any,Any>){

    val uniqueBtn1Txt=unique+"Btn1TXT"
    insideMap[uniqueTxt]=R.string.$uniqueBtn1TXT

}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

yes you can with this code:

val key = "some_key"
val id = context.resources.identifier(key, "string", context.packageName)
val text = context.getString(id)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading