Android Question How to choose component from a group of components in a panel

Mooney

New Member
I have a question on how to select a checkbox from multiple checkboxes in a panel. I have searched the forums but haven't found the answer yet so if someone can post a link or help I would appreciate it. I'll try to simplify my problem as best as possible..... Say I have 10 checkboxes in a panel (named Panel1). Each checkbox follows a naming pattern such as 'abc1abc' where the number in the middle is different between each checkbox, from 1 to 10, so the last checkbox is named abc10abc. Each checkbox has its tag set to the same number in the name, so the second checkbox is 'abc2abc' and has tag 2, and so on. I want to disable one or more of those checkboxes based on a value found in a global array, say Starter.DisableBox(10) As String. I can cycle through the array and if the letter Y is found then I want to disable the corresponding checkbox. So if Starter.DisableBox(4) has value Y in it, how do I select the abc4abc checkbox to disable it? I'm sure it's not hard, I just can't figure out the answer yet. Any help would be appreciated.
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
I am not sure that I understand your setup exactly, but I think that you are overcomplicating it. Using Tag values is the right idea, but the names of the checkboxes are irrelevant.
Try putting your checkboxes into a list, something like this ...
B4X:
Sub Globals
    . . . .
    Dim checkboxes As List
End Subsub

' Add all checkboxes in panel [p] to a list
Sub setupCheckboxes(p As Panel)
    checkboxes.Initialize
    For Each v As View In p.GetAllViewsRecursive
        If v Is CheckBox Then  checkboxes.Add(v)
    Next   
End Sub
Then you can easily disable any box given its Tag value ...
B4X:
Sub disableCheckbox(n As Int)
    For Each c As CheckBox In checkboxes
        If (n = c.Tag) Then c.Enabled = False
    Next
End Sub
You might not be able to use this code exactly, but I hope that it will give you an idea of how to achieve what you want.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…