I want to create the 96 buttons to the List View, just wanna find the simple way to create. I think my code so complicated.
How to use the "for ... next" to simple create the buttons?
Please help me.
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim ScrollView1 As ScrollView
Dim lst_b As List
Dim height As Int
height=50dip
End Sub
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
If FirstTime=True Then
ScrollView1.Initialize(0)
Dim pnl As Panel
pnl=ScrollView1.Panel
Activity.AddView(ScrollView1,0,0,100%x,100%y)
lst_b.Initialize
For i = 1 To 1
Dim b As Button
b.Initialize("button")
b.text=i
lst_b.Add(b)
pnl.AddView(b,0%x,0,15%y,height)
Next
For i = 2 To 2
Dim b As Button
b.Initialize("button")
b.text=i
lst_b.Add(b)
pnl.AddView(b,20%x,0,15%y,height)
Next
For i = 3 To 3
Dim b As Button
b.Initialize("button")
b.text=i
lst_b.Add(b)
pnl.AddView(b,40%x,0,15%y,height)
Next
For i = 4 To 4
Dim b As Button
b.Initialize("button")
b.text=i
lst_b.Add(b)
pnl.AddView(b,60%x,0,15%y,height)
Next
For i = 5 To 5
Dim b As Button
b.Initialize("button")
b.text=i
lst_b.Add(b)
pnl.AddView(b,80%x,0,15%y,height)
Next
For i = 6 To 6
Dim b As Button
b.Initialize("button")
b.text=i
lst_b.Add(b)
pnl.AddView(b,0%x,120,15%y,height)
Next
For i = 7 To 7
Dim b As Button
b.Initialize("button")
b.text=i
lst_b.Add(b)
pnl.AddView(b,20%x,120,15%y,height)
Next
For i = 8 To 8
Dim b As Button
b.Initialize("button")
b.text=i
lst_b.Add(b)
pnl.AddView(b,40%x,120,15%y,height)
Next
For i = 9 To 9
Dim b As Button
b.Initialize("button")
b.text=i
lst_b.Add(b)
pnl.AddView(b,60%x,120,15%y,height)
Next
For i = 10 To 10
Dim b As Button
b.Initialize("button")
b.text=i
lst_b.Add(b)
pnl.AddView(b,80%x,120,15%y,height)
Next
For i = 11 To 11
Dim b As Button
b.Initialize("button")
b.text=i
lst_b.Add(b)
pnl.AddView(b,0%x,240,15%y,height)
Next
For i = 12 To 12
Dim b As Button
b.Initialize("button")
b.text=i
lst_b.Add(b)
pnl.AddView(b,20%x,240,15%y,height)
Next
For i = 13 To 13
Dim b As Button
b.Initialize("button")
b.text=i
lst_b.Add(b)
pnl.AddView(b,40%x,240,15%y,height)
Next
For i = 14 To 14
Dim b As Button
b.Initialize("button")
b.text=i
lst_b.Add(b)
pnl.AddView(b,60%x,240,15%y,height)
Next
For i = 15 To 15
Dim b As Button
b.Initialize("button")
b.text=i
lst_b.Add(b)
pnl.AddView(b,80%x,240,15%y,height)
Next
For i = 16 To 16
Dim b As Button
b.Initialize("button")
b.text=i
lst_b.Add(b)
pnl.AddView(b,0%x,360,15%y,height)
Next
pnl.Height=lst_b.Size*height
End If
End Sub
How to use the "for ... next" to simple create the buttons?
Please help me.
Last edited: