Can I create an enum
or a sealed class
in Kotlin
that contain string resources?
For instance, I have this class:
private enum class Item(
val id: Int,
@DrawableRes val imageRes: Int,
val title: String
) {
PURSE(1, R.drawable.ic_card, "My balance"),
MESSAGES(2, R.drawable.ic_bell, "Messages")
}
If I add a field val resources: Resources
in the constructor, I cannot set a parameter resources
, so cannot use string resources from strings.xml
. In this case I cannot use localization for enum
s.
You don't need a Resources instance. You can use a string resource, like you did for the drawable:
private enum class Item(
val id: Int,
@DrawableRes val imageRes: Int,
@StringRes val title: Int
)
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