I am trying to implement the code in Erel's CustomListView tutorial but I cannot understand something.
I don't fully understand the customlistview add line. After the sub Createlistitem has created the panel there is the item height and then
Isn't this already in the panel? What is the purpose of this field?
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
clv1.AddTextItem("Aaaa", "a")
clv1.AddTextItem("Aaaa" & CRLF & "Bbbb", "b")
clv1.AddTextItem("Aaaa" & CRLF & "Bbbb" & CRLF & "Cccc", "c")
clv1.AddTextItem("Aaaa" & CRLF & "Bbbb" & CRLF & "Cccc" & CRLF & "Dddd" , "d")
clv1.AddTextItem("Aaaa" & CRLF & "Bbbb" & CRLF & "Cccc" & CRLF & "Dddd" & CRLF & "Eeee", "e")
'Second list is created programmatically.
'Create 20 items made of a label, button and checkbox.
clv3.Initialize(Me, "clv3")
Activity.AddView(clv3.AsView, 0, 50%y, 100%x, 50%y)
For i = 1 To 10
clv3.Add(CreateListItem("Item #" & i, clv3.AsView.Width, 50dip), 50dip, "Item #" & i)
Next
End Sub
Sub clv1_ItemClick (Index As Int, Value As Object)
Activity.Title = Value
End Sub
Sub clv3_ItemClick(Index As Int, Value As Object)
Log(Index & " = " & Value)
End Sub
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
Dim p As Panel
p.Initialize("")
p.Color = Colors.Black
Dim b As Button
b.Initialize("button") 'all buttons click events will be handled with Sub Button_Click
Dim chk As CheckBox
chk.Initialize("chk")
Dim lbl As Label
lbl.Initialize("")
lbl.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.LEFT)
lbl.Text = Text
lbl.TextSize = 16
lbl.TextColor = Colors.White
b.Text = "Click"
p.AddView(lbl, 5dip, 2dip, 150dip, Height - 4dip) 'view #0
p.AddView(b, 155dip, 2dip, 110dip, Height - 4dip) 'view #1
p.AddView(chk, 280dip, 2dip, 50dip, Height - 4dip) 'view #2
Return p
End Sub
B4X:
"Item #" & i