Android Question Retrieve the list of specific view in one activity

Yayou49

Active Member
Licensed User
Hi,

In one activity, I add, by code, some checkbox as following:


B4X:
For i = 1 to 10
 Dim Chk As CheckBox
 Chk.Initialize("")
 Chk.Text = "CH" & i
 Chk.Tag = i
 Activity.AddView(Chk,2%x,1%y *i,90%x,10%x)
Next

After this code running, some checkbox are set on and some are set off.

Now, I need to create a list with all checked Checkbox.

I've tried to do that:

B4X:
Dim Result as String
For Each V As CheckBox In Activity.GetAllViewsRecursive
        If v.tag <> "" or v.tag <> Null Then
                If V.Checked = True Then
                    Result = Result & V.Tag
                End If
        End If        
Next

My problems are:
- In the loop "For Each V As CheckBox In Activity.GetAllViewsRecursive",
it seems all views are taking in account, not only CheckBox view
- for some views (exept CheckBox views), V.tag has no value but this value is not "" or Null

So, what should be the best solution to retrieve the list of CheckBox view in my activity and what about value of tag, only if there is a value ???....
 

Yayou49

Active Member
Licensed User
For v.tag values, I've the solution:

B4X:
If IsNumber(v.tag) Then

Now only one problem, the list of CheckBox ....
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
something like

B4X:
For Each V As View In Activity.GetAllViewsRecursive
if v is Checkbox then
    dim chk as Checkbox = v
        If chk.tag <> "" or chk.tag <> Null Then
                If chk.Checked = True Then
                    Result = Result & chk.Tag
                End If
        End If       

else
        If v.tag <> "" or v.tag <> Null Then
                If V.Checked = True Then
                    Result = Result & V.Tag
                End If
        End If       
end if
Next
 
Upvote 0
Top