Android Question Radio buttons list problem

Alex_197

Well-Known Member
Licensed User
Longtime User
Hi, I have a problem.

I need to show a list of radiobuttons. But if I just add them into a ScrollView only one radiobutton can be selected.

I need it like this

Do you have a symptom 1
Yes No

Do you have a symptom 2
Yes No

Do you have a symptom 3
Yes No

So I decided to add a pare of radio buttons into a panel and then add a panel with radio buttons inside into a scroll view.

The problem is that panel looks Ok with 2 radio buttons inside but 2 others are empty (at least they are look like this)

If I try to loop trough all views inside a scroll view I can see all my radio buttons but why they are not shown?

Here is my code and also I attached my project.

Radio buttons list:
#Region  Project Attributes
    #ApplicationLabel: Radio Buttons
    #VersionCode: 1
    #VersionName: 1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private svList As ScrollView
    Private btnNext As Button
    Private lblTitle As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Symptoms")
End Sub

Sub Activity_Resume
    Try
    CreateList
    Catch
        Log(LastException)
    End Try
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub CreateList
    Try
        
        Dim j As Int
        Dim ItemHeight As Int
        Dim Qty As Int
        Dim txt As String
        
        
        Qty=3
        ItemHeight=65dip
        
        For i=1 To Qty
            Dim cd As ColorDrawable
            
            cd.Initialize2(Colors.white,5dip,2dip,Colors.Black)
            
            j=j+1
            
            
            txt="Radio " & i
            
            Dim rbYes As RadioButton,rbNo As RadioButton
            Dim pan As Panel
        
            rbYes.Initialize("")
            rbNo.Initialize("")
            pan.Initialize("")
            pan.Background=cd
            
            rbYes.Text=txt & " " & "YES"
            rbNo.Text=txt &  " " & "NO"
            rbYes.Tag=txt & " " & "YES"
            rbNo.Tag=txt &  " " & "NO"
            rbYes.TextSize=14
            rbNo.TextSize=14
            rbYes.TextColor=Colors.Red
            rbNo.TextColor=0xFF048904
            rbYes.Enabled=True
            rbNo.Enabled=True
                    
            pan.AddView(rbYes, 0, ItemHeight * (j-1), svList.Width/2.5, ItemHeight - 8dip)
            pan.AddView(rbNo, svList.Width/2, ItemHeight * (j-1), svList.Width/2.5, ItemHeight - 8dip)
            
            svList.Panel.AddView(pan,0,ItemHeight * (j-1), svList.Width, ItemHeight - 8dip)
            
        Next
        
        svList.Panel.Height= ItemHeight *j
        
    Catch
        Log(LastException)
    End Try
End Sub



Sub btnNext_Click
    Try
        
        For Each v As View In svList.Panel.GetAllViewsRecursive
            Log(v.Tag)
        Next
        
    Catch
        Log(LastException)
    End Try
End Sub
 

Attachments

  • RadioButtons.zip
    9.9 KB · Views: 299

Alex_197

Well-Known Member
Licensed User
Longtime User
Problem solved - lines 85 and 86 should be like these

B4X:
pan.AddView(rbYes, 0, 0, svList.Width/2.5, ItemHeight - 8dip)
pan.AddView(rbNo, svList.Width/2, 0, svList.Width/2.5, ItemHeight - 8dip)
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Problem solved - lines 85 and 86 should be like these
Hi Alex:
I am glad you solved it, but I think you are better off using an xCLV with a bunch of B4XSwitch (several) and a labels corresponding to each symptom.
One B4XSwitch will take care of the Yes and No, as opposed to radio buttons where you need one for Yes and one for No.
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Hi Alex:
I am glad you solved it, but I think you are better off using an xCLV with a bunch of B4XSwitch (several) and a labels corresponding to each symptom.
One B4XSwitch will take care of the Yes and No, as opposed to radio buttons where you need one for Yes and one for No.
Thank you for your replay. Can you show some examples?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Thank you for your replay. Can you show some examples?
Here is a quick example with the attached project that shows you when doing it with xClv and B4XSwitchto. It gives you an idea. For your application, you will have to refine it and expand it. with possibly custom type and maybe lazy loading to make it better. Take it from an expert on xClv ( I am being sarcastic of course, I still have a lot to learn on xClv and lazy loading as demonstrated a few days ago in my struggles with a recent thread pertinent to lazy loading)
 

Attachments

  • B4XSwitchandSymptoms.png
    B4XSwitchandSymptoms.png
    18.2 KB · Views: 291
  • xClvB4XSwitchForAlex.zip
    10.7 KB · Views: 278
Upvote 0

udg

Expert
Licensed User
Longtime User
Upvote 0

ilan

Expert
Licensed User
Longtime User
Because it's possible to check Yes AND No at the same time. But with Radio button you can select either Yes OR No.

Klaus means use 1 CheckBox instead of 2 radio buttons. NOT 2 CheckBoxs instead of 2 radio buttons.
i agree with klaus it would look much better. and you can also use b4xswitch, this will make it simpler to transport the project to b4i in the future.
 
Upvote 0
Top