I have a simple enum class in which I try to override the toString method. However I would like to connect it to R.string values and there is where my problem starts.
All methods I tried to use, work with @Composable functions. I tried find some ways without over context but those were also all composable. I have no clue.
If I add composable connotation I get the error:
@Composable annotation mismatch with overridden function: @Composable public open fun toString(): String defined in com.blblbla. Season, public open fun toString(): String defined in kotlin.Enum
enum class Season{
Spring,
Summer,
Autumn,
Winter;
@Composable
override fun toString(): String {
return when (this) {
Spring -> stringResource(R.string.Spring)
Summer -> stringResource(R.string.Summer)
Autumn -> stringResource(R.string.Autumn)
Winter -> stringResource(R.string.Winter)
}
}
}
I tried to import Context, but this did not work since I can’t get a Context assigned.
context: Context = LocalContext.current <- composable function again.
context.resources.getString(R.string.Spring)
I just run in circles with asking the ais. I don’t know why it shall be so hard to get a function to link to strings.xml.android without invoking any composables.
user24812055 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.