Could you please help me work this out? I have thr...
# getting-started
n
Could you please help me work this out? I have three buttons and when I select one, I want the other two to be disabled until I unselect it. I can't figure out out to put that into code. I thought that this would work (at least for the first button):
Copy code
if (option.id == 0) {
                for (o in listOfOptions) {
                    when (o.id) {
                        1 -> enabled = false
                        2 -> enabled = false
                    }
                }
            }
But all my 3 buttons are disabled when I do this... 🤔
s
What is
enabled
? Should it be something like
o.enabled
instead?
Based on what you described, I would expect something more like:
Copy code
for (o in listOfOptions) {
    o.enabled = (o.id == 0)
}
n
ah yes, that worked!
I mean
o.enabled
worked
but the code you suggest looks a lot better. Thanks!
p
depending on your UI framework, there might also be a way to state “these buttons are mutually exclusive” that’s cleaner to implement/read
n
I'm using Jetpack Compose.
The problem with Radio Buttons is that the user does not need to switch one off in order to use the other ones.
c
that’s not right - by definition, radio buttons are mutually exclusive. In contrast to say checkboxes where multiples can be selected.
n
Ah, yes, I see what you mean. Ok, that's the way to go! Cheers.