checkbox list

m0narX

Member
Licensed User
Longtime User
I need to create a scrollable list consisting of dynamically added checkboxs, how to do this?
Below, I gave an example, but I can `t get clicked checkbox
B4X:
Dim Modules As List
Dim ModuleView As ScrollView
Dim ModuleM As CheckBox
Dim HPos As Int
Modules=File.ListFiles("/sdcard/modules")
HPos = 0
For i=0 TO Modules.Size-1
Dim ModuleName As String
ModuleName=Modules.Get(i)
ModuleM.Initialize("event1")
ModuleM.Text=ModuleName
ModuleList.Panel.AddView(ModuleM, 10, HPos, 300, 50)
HPos = HPos + 60
Next
ModuleList.Panel.Height = HPos

I also thought about using the ListView, but it does not change the properties of an element (eg to change the label item)
 

m0narX

Member
Licensed User
Longtime User
Necessary that the next time you open, flags have placed themselves (in line with what was selected last time).
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This will help you get started:
B4X:
'Activity module
Sub Process_Globals
    
End Sub

Sub Globals
    Dim ItemHeight As Int
    ItemHeight = 40dip
    Dim ScrollView1 As ScrollView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    ScrollView1.Initialize(0)
    Activity.AddView(ScrollView1, 0, 0, 100%x, 80%y)
    Dim Button1 As Button
    Button1.Initialize("Button1")
    Button1.Text = "Show selected"
    Activity.AddView(button1, 25%x, 82%y, 50%x, 10%y)
    CreateList(50)
End Sub
Sub Button1_Click
    Dim sb As StringBuilder
    sb.Initialize
    sb.Append("Selected items:").Append(CRLF)
    For i = 0 To ScrollView1.Panel.NumberOfViews - 1
        Dim chk As CheckBox
        chk = ScrollView1.Panel.GetView(i)
        If chk.Checked Then sb.Append(chk.Text).Append(CRLF)
    Next
    Msgbox(sb.ToString, "")
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub CreateList(NumberOfItems As Int)
    ScrollView1.Panel.Height = ItemHeight * NumberOfItems
    For i = 1 To NumberOfItems
        Dim chk As CheckBox
        chk.Initialize("")
        chk.Text = "CheckBox" & i
        ScrollView1.Panel.AddView(chk, 0, ItemHeight * (i-1), ScrollView1.Width, ItemHeight - 2dip)
    Next
End Sub

09_12_10_1.png
 
Upvote 0
Top