0

I'm developing an app which having level and each level will have different symbol and background color. For example, level 1 will have R.drawable.circle, R.drawable.red_background. Is it possible to store in enum with range like

enum class LevelEnum(levelSymbol: Int, levelColor: Int) {
    1..21(R.drawable.circle, R.drawable.red_background),
    22..50(R.drawable.rectangle, R.drawable.blue_background),
    ....
}
1
  • Is there a reason you specifically ask for an enum class? Commented Apr 27, 2021 at 15:23

1 Answer 1

2

In such case you can use function with when and return the drawble when your levelSymbol is in your desired range.

fun levelSymbol(levelSymbol: Int): Int {
        return when (levelSymbol) {
            in 1..21 -> R.drawable.circle
            in 22..50 -> R.drawable.rectangle
            else -> R.drawable.circle
        }
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for you suggestion, much appreciate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.