Android Question [solved] Obtaining the values of all the switch buttons in the CustomListView

ThePuiu

Active Member
Licensed User
Longtime User
I have a CustomListView that contains in each panel a label and a B4XSwitch. I'm trying to get the status (on or off) of all the B4XSwitch buttons that the list contains. I tried the code:
B4X:
For i = 0 To clv.GetSize - 1
        Dim p As Panel = clv.GetPanel(i)
        For Each v As View In p.GetAllViewsRecursive
            If v Is Label Then
                Dim lbl As Label = v
                selectedMarimi.Add(lbl.Text)
            End If
            If v Is B4XSwitch Then
                Dim sw As B4XSwitch = v
                selectedValues.Add(sw.Tag)
            End If
        Next
Next
but the line: Dim sw As B4XSwitch = v gives an error: Types do not match. How can I identify the button?
Another problem (not so disturbing) is that the list panels overlap over the list border...I was unable to set them correctly .... (see attached picture)
B4X:
Dim p As Panel
    p.Initialize("")
    p.Tag = i
    p.SetLayout(0, 0, clv.AsView.Width, 40dip)
    p.LoadLayout("itemDrawerGrafice")
 

Attachments

  • Screenshot_20200105-215851.jpg
    Screenshot_20200105-215851.jpg
    103.3 KB · Views: 189

ThePuiu

Active Member
Licensed User
Longtime User
I solved the first part of the problem by finding the following indication:

B4X:
For i = 0 To clv.GetSize - 1
        Dim p As Panel = clv.GetPanel(i)
        Dim lbl As Label = p.GetView(0)
        Dim chk As B4XView  = p.GetView(1) 
        Dim checked As B4XSwitch = chk.Tag
        If checked.Value Then
            selectedValues.Add(checked.Tag)
            selectedMarimi.Add(lbl.Text)
        End If      
    Next

the problem of "aesthetics" remains !
 
Upvote 0
Top