Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private CLV1 As CustomListView
Dim Xui As XUI 'I am surprised that this is possible
End Sub
Sub CreateLabelButton(Width As Int, Height As Int, BackColor As Int, LabelText As String, ButtonText As String) As B4XView
Dim Pnl1 As B4XView = Xui.CreatePanel("")
Pnl1.Width = Width
Pnl1.Height = Height
Pnl1.Color = BackColor
Dim Lbl1 As Label
Lbl1.Initialize("")
Lbl1.Text = LabelText
Lbl1.TextColor = Colors.Blue
Lbl1.Color = Colors.Gray
Lbl1.Gravity = Gravity.CENTER
Pnl1.AddView(Lbl1, 10dip, 10dip, Width / 2 - 20dip, Height - 20dip)
Dim Btn1 As Button
Btn1.Initialize("")
Btn1.Text = ButtonText
Btn1.Height = Pnl1.Height - 20dip
Pnl1.AddView(Btn1, Width / 2 + 10dip, 10dip, Width / 2 - 20dip, Height - 20dip)
Return Pnl1
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
'CLV1.DefaultTextBackgroundColor=Colors.Gray
Dim LabButWidth As Int = CLV1.AsView.Width
Dim LabButHeight As Int = LabButWidth / 3 'aspect ratio 3:1
For I = 1 To 100
Dim LabButBackColor As Int = Colors.RGB(Rnd(1, 4) * 51, Rnd(1, 4) * 51, 0)
Dim LabBut As B4XView = CreateLabelButton(LabButWidth, LabButHeight, LabButBackColor, "Label " & I, "Button " & I)
CLV1.Add(LabBut, I)
Next
End Sub