Android Question CheckBox in CLV problem


Active Member
Licensed User
I have a CLV with a checkbox as a first item


I want to check the check box when i click inside it or when i click in clvItem,
and a checkAll checkbox to select all or Deselect All when i clicked in checkbox/label select All

I have trouble when using both checkBox or clvStudents_ItemClick, I cant set both of them. It seems that the one disable the other.
What i have done until now is the bellow code and works.

Private chkAllDisable as Boolean

Private Sub clvStudents_ItemClick (Index As Int, Value As Object)
    ' Do something with Value
'    change checkbox
    Dim pnl As B4XView = clvStudents.GetPanel(Index)
    pnl.GetView(0).Checked = Not(pnl.GetView(0).Checked)
    'This is to uncheck chkAll
    If chkAll.Checked Then
        chkAllDisable = True
        chkAll.Checked = False
    End If
End Sub

Private Sub chkAbs_CheckedChange(Checked As Boolean)
    ' I dont know what to do here

End Sub

Private Sub chkAll_CheckedChange(Checked As Boolean)
    If Not(chkAllDisable) Then
        For i = 0 To clvStudents.Size-1
            Dim pnl As B4XView = clvStudents.GetPanel(i)
            pnl.GetView(0).Checked = Checked
            If Checked Then
                ' DO something with Value(i)
                ' DO something with Value(i) 
            End If
    End If
End Sub

Private Sub lblSelectAll_Click
    chkAllDisable = False
    chkAll.Checked = Not(chkAll.Checked)
End Sub

Any idea how to make this happen or an other approaching method?
Thank you all


Staff member
Licensed User

Complete code:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private CustomListView1 As CustomListView
    Private CheckboxIndex As Int = 0
End Sub

Public Sub Initialize
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Dim cs As CSBuilder
    AddItem(cs.Initialize.Color(0xFFFFA100).Bold.Append("Select All / Deselect All").PopAll)
    For i = 1 To 30
        AddItem(cs.Initialize.Bold.Append($"Item #${i}"$).PopAll)
End Sub

Private Sub AddItem(Text As Object)
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, CustomListView1.AsView.Width, 35dip)
    XUIViewsUtils.SetTextOrCSBuilderToLabel(p.GetView(CheckboxIndex), Text)
    CustomListView1.Add(p, "")
End Sub

Private Sub CustomListView1_ItemClick (Index As Int, Value As Object)
    Dim Index As Int = CustomListView1.GetItemFromView(Sender)
    Dim chk As B4XView = CustomListView1.GetPanel(Index).GetView(CheckboxIndex)
    chk.Checked = Not(chk.Checked)
End Sub

Private Sub CheckBox1_CheckedChange(Checked As Boolean)
    Dim index As Int = CustomListView1.GetItemFromView(Sender)
    If index = 0 Then
    End If
End Sub

Private Sub SelectAllStateChangedByUser
    Dim state As Boolean = CustomListView1.GetPanel(0).GetView(CheckboxIndex).Checked
    For i = 1 To CustomListView1.Size - 1
        CustomListView1.GetPanel(i).GetView(CheckboxIndex).Checked = state
End Sub


    14.9 KB · Views: 28
Upvote 0