Below is exact code from Erel's xCustomListView tutorial, to which I've added an additional line adding a list item and a subroutine for that list item (both indicated with lines of asterisks). I know that the format of this additional item and subroutine are not exactly what Erel shows in the tutorial, but can anyone tell me what it is about my extra code that doesn't add a visible entry at the end of the clv2 list? In other words, my code does nothing to change the appearance of the original code when run, and I'd love to know why.
Thanks!
Thanks!
B4X:
#Region Project Attributes
#ApplicationLabel: xCLV
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
Private clv1 As CustomListView
Private clv2 As CustomListView
Private Label1 As B4XView
Private CheckBox1 As B4XView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
clv1.AddTextItem("1Aaaa" & CRLF & "Bbbb", "b")
clv1.AddTextItem("2Aaaa" & CRLF & "Bbbb" & CRLF & "Cccc", "c")
clv1.AddTextItem("3Aaaa" & CRLF & "Bbbb" & CRLF & "Cccc" & CRLF & "Dddd" , "d")
clv1.AddTextItem("4Aaaa" & CRLF & "Bbbb" & CRLF & "Cccc" & CRLF & "Dddd" & CRLF & "Eeee", "e")
For i = 1 To 20
clv2.Add(CreateListItem($"Item #${i}"$, clv2.AsView.Width, 60dip), $"Item #${i}"$)
Next
'*********************** My added line ******************************
clv2.Add(CreateLabelListItem("My Label",clv2.GetBase.Width,40dip),"")
'********************************************************************
End Sub
Sub Clv1_ReachEnd
Log("reach end")
clv1.AddTextItem($"New item: $Time{DateTime.Now}"$, "New Item")
End Sub
Sub clv1_ItemClick (Index As Int, Value As Object)
Activity.Title = Value
clv1.AsView.BringToFront
End Sub
Sub clv2_ItemClick(Index As Int, Value As Object)
clv2.AsView.BringToFront
Log(Index & " = " & Value)
clv2.InsertAt(Index, CreateListItem($"Item !!!"$, clv2.AsView.Width, 60dip), $"Item !!!"$)
End Sub
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
Dim p As Panel
p.Initialize("")
p.SetLayout(0, 0, Width, Height)
p.LoadLayout("CellItem")
Label1.Text = Text
Return p
End Sub
Sub CheckBox1_CheckedChange(Checked As Boolean)
Dim index As Int = clv2.GetItemFromView(Sender)
Dim pnl As B4XView = clv2.GetPanel(index)
Dim chk As B4XView = pnl.GetView(2)
MsgboxAsync($"Item value: ${clv2.GetValue(index)}
Check value: ${chk.Checked}"$, "")
End Sub
Sub Button1_Click
Dim index As Int = clv2.GetItemFromView(Sender)
Dim pnl As B4XView = clv2.GetPanel(index)
Dim lbl As B4XView = pnl.GetView(0)
Dim chk As B4XView = pnl.GetView(2)
lbl.Text = "Clicked!"
'Msgbox("Item value: " & clv2.GetValue(index) & CRLF & "Check value: " & chk.Checked, "")
Dim checkedItems As List
checkedItems.Initialize
For i = 0 To clv2.GetSize - 1
Dim p As B4XView = clv2.GetPanel(i)
Dim chk As B4XView = p.GetView(2)
If chk.Checked Then
checkedItems.Add(clv2.GetValue(i))
End If
Next
Log("Checked items: " & checkedItems)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
'*********************** My added routine ******************************
Sub CreateLabelListItem(txt1 As String, wid As Int, hgt As Int) As Panel
Dim pn As Panel
pn.Initialize("")
pn.Color=Colors.White
Dim lbl1 As Label
lbl1.Initialize("")
lbl1.TextColor=Colors.Black
lbl1.TextSize=16
lbl1.Text=txt1
pn.AddView(lbl1,0,0,wid,hgt)
Return pn
End Sub
'**********************************************************************