I tried a lot of combinations, but somehow I don't get it.
The id for the text I want to show is generated.
I need to write a variable here instead of a concrete id.
So not:
getString(R.string.id_1)
But something like:
var myId = ...
getString(R.string."$myId")
Do you know what I mean? What ever I tried I got an error that only an Int.
How would you solve this in Kotlin?
Try below code, it will work for you:
fun AppCompatActivity.getString(name: String): String {
return resources.getString(resources.getIdentifier(name, "string", packageName))
}
Usage: val resource = getString($resourceName);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With