B4J Question ABMRadioGroup - Clearing options

Rob White

Member
Licensed User
Hi all,
I need to select a clients farm once I have the selected client. So the farms radio group must be dynamic.
Here is a modified copy of the page template ConnectPage sub and the clicked event handler for the client group.
Note that this is all hard coded my code gets this information from a DB.

B4X:
public Sub ConnectPage()           
    '    connecting the navigation bar
    ABMShared.ConnectNavigationBar(page)

    Dim rbclient As ABMRadioGroup
    rbclient.Initialize(page,"rbClient","mytheme")
    rbclient.AddRadioButton("Client1",True)
    rbclient.AddRadioButton("Client2",True)
    rbclient.AddRadioButton("Client3",True)
    Dim Clab As ABMLabel
    Clab.Initialize(page,"lab1","Select client",ABM.SIZE_H5,False,"mytheme")
    
    page.Cell(1,1).AddComponent(Clab)
    page.Cell(2,1).AddComponent(rbclient)
    ' refresh the page
    page.Refresh
    
    ' Tell the browser we finished loading
    page.FinishedLoading
    ' restoring the navigation bar position
    page.RestoreNavigationBarPosition   

End Sub

Sub rbclient_clicked(target As String)
    'This is from the demo BUT has wrong number of arguments >> Dim rb As ABMRadioGroup = page.Component(2,1,"rbgroup")
    Dim rb As ABMRadioGroup = page.Component("rbClient")
    Dim rbFarms As ABMRadioGroup
    rbFarms.Initialize(page,"rbFarms","mytheme")
    Log($"Inside rbclient_clicked getActive = ${rb.GetActive}"$)
    Select rb.GetActive
        Case 0
            rbFarms.AddRadioButton("Farm 1",True)
            rbFarms.AddRadioButton("Farm 2",True)
        Case 1
            rbFarms.AddRadioButton("Farm 3",True)
            
        Case 2
            rbFarms.AddRadioButton("Farm 4",True)
            rbFarms.AddRadioButton("Farm 5",True)
            rbFarms.AddRadioButton("Farm 6",True)
            
    End Select
    page.Cell(2,2).AddComponent(rbFarms)
    page.Refresh
End Sub

I can supply the complete template zip if requested.

My questions are about how I make the dynamic Farms rb group. I assumed that because the rbFarms radiogroup is declared in the click handler a new group would be formed but when run only the first formed group is displayed.
There is no clear method so how would people do this?
 

Harris

Expert
Licensed User
Longtime User
Easiest is probably first removing the old radiogroup and adding it again with the new client specific values using the Page.Cell(2,2).RemoveAllComponents method
That is the way I learned to do it. Remove the default component in the row / cell and add the new based on your update.
A simple refresh of row / cell doesn't work, as expected since - I think - the cache "seems to see it" as the same. Removing the component forces a new look at the content.
When one learns how to deal with these peculiar issues, it gets locked into your dev knowledge working with ABM....
 
Upvote 0
Top