Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

271
Views
Enums or sealed classes with strings

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 enums.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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
)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!