B4J Question Radio Button Selected - not working

tcgoh

Active Member
Licensed User
Longtime User
Hi,

I am having problem with radio Button rbtn.selected or rbtn.selected = true
Both are not showing any result. Anyone has the same problem?

Thanks
 

tcgoh

Active Member
Licensed User
Longtime User
Uploaded. Just a small part of my project.
Thanks for looking into it.
 

Attachments

  • radioBtn.zip
    1.2 KB · Views: 399
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It seems to work as expected. It prints AAA to the logs.

Do you expect it to print BBB when you press on the second RB? It will not happen as your code only runs when the program starts. You should handle the CheckedChange event:
B4X:
Sub RbBtnA_CheckedChange(Checked As Boolean)
   
End Sub
Sub RbBtnB_CheckedChange(Checked As Boolean)
   
End Sub
 
Upvote 0

tcgoh

Active Member
Licensed User
Longtime User
Sorry Erel, I can't get the code to work even with the RbBtnA_checkedchange, appreciate if you could guide me with the code. Thanks

Yes, I was trying to get the Label to Change or print BBB with the second Button.
 
Upvote 0

AndrewW

Member
Licensed User
Longtime User
Hi. I am a newby, having just downloaded B4A. I have purchased a manual, but am impatient to get going. I have got my first app up and sort of running. However, I am experiencing the same problem as above. I have added three radio buttons, r1, r2, r3 with code like:

Sub Activity_Create(FirstTime AsBoolean)

Dim r1,r2,r3 As RadioButton
r1.Initialize("Radio")
r2.Initialize("Radio")
r3.Initialize("Radio")
Activity.AddView(r1,200dip,700dip,60dip,60dip)
Activity.AddView(r2,400dip,700dip,60dip,60dip)
Activity.AddView(r3,600dip,700dip,60dip,60dip)
r3.Checked = True
End Sub

Sub r1_ChangeChecked(Checked AsBoolean)

Msgbox("Start","")

End Sub

When the app starts, r3 is selected OK.
Pressing r1 cancels r3 and selects r1

"Start" message never appears.

What am I doing wrong?
Can someone point me at an appropraite help file?
 
Upvote 0

MaFu

Well-Known Member
Licensed User
Longtime User
Using the variable name for the event is not correct. You tell the radio button the event name on initialize.
Therefore you should different names on initialize:
B4X:
r1.Initialize("Radio1")
r2.Initialize("Radio2")
r3.Initialize("Radio3")
And then create the event subs:
B4X:
Sub Radio1_ChangeChecked(Checked AsBoolean)
    ...
End Sub
Sub Radio2_ChangeChecked(Checked AsBoolean)
    ...
End Sub
Sub Radio3_ChangeChecked(Checked AsBoolean)
    ...
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
As you set the Event name as "Radio" the ChangeChecked routine must be like this:
B4X:
Sub Radio_ChangeChecked(Checked AsBoolean)
    Dim rbt As RadioButton
    rbt = Sender   'gets the RadioButton which raised the event
    Msgbox("Start","")
End Sub
 
Upvote 0
Top