Android Question Confused about Radiobuttons

kdgarris

Member
Licensed User
Longtime User
I'm trying to figure out how to best make use of radiobuttons. I understand that all radiobuttons with the same parent will be in the same group in terms of only one being selected at a time. However, events don't seem to work in the way that I'd want or expect, and I'm not sure if there's a way to change that.

Specifically, if I generate subs for these radiobuttons getting checked or unchecked, each one has its own sub. Ideally what I would like is to have one sub that is invoked if any of them are selected, and have a way within that sub to see which one is now checked. I think this would be much cleaner and more elegant.

Is there a way to accomplish this? Thanks in advance for any advice for a newbie. :)
 

derez

Expert
Licensed User
Longtime User
Give the radiobuttons the same event name (you can give them different tags), hence one sub only for this event.
Use the sender keyword to find the selected radiobutton and take action accordingly.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Also, if you need to know which one is the sender, use the tag property for each radio button.
Then you can use something like:
B4X:
Dim myRButton as RadioButton = Sender
If myRButton.tag = "xpto" then...
 
Upvote 0
Top