Sub Globals
'These global variables will be redeclared each time the activity is created.
Private Clv1 As CustomListView
Private Label1 As Label
Private PCLV As PreoptimizedCLV
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
' Initializing PCLV with your CustomListView
PCLV.Initialize(Me, "PCLV", Clv1)
For i = 0 To 200 'Increased to 200
'We're not creating the panel here, we're just adding a virtual item
PCLV.AddItem(140dip, xui.Color_White, "Item description " & i)
Next
' Validation
PCLV.Commit
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
MsgboxAsync("Hello world!", "B4X")
End Sub
' Managing the rendering of visible items
Private Sub Clv1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
For Each i As Int In PCLV.VisibleRangeChanged(FirstIndex, LastIndex)
Dim item As CLVItem = Clv1.GetRawListItem(i)
Dim pnl As B4XView = xui.CreatePanel("")
item.Panel.AddView(pnl, 0, 0, item.Panel.Width, item.Panel.Height)
'Load your item layout
pnl.LoadLayout("main_item")
Label1.Text = item.Value
Next
End Sub
'Click on an item
Private Sub Clv1_ItemClick (Index As Int, Value As Object)
Log("Item " & Index & " clicked, value=" & Value)
End Sub
' Click on a button in the item
Private Sub BtnItem_Click
Dim Index As Int = Clv1.GetItemFromView(Sender)
Log("Button in item " & Index & " clicked")
End Sub