Sub Activity_Create(FirstTime As Boolean)
MyList.Initialize
MyList=Array ("p1.jpg","p2.jpg","p3.jpg","p4.jpg","p5.jpg","p6.jpg")
Activity.LoadLayout("layMain") 'has CustomListView1 only
For i = 1 To 100 'works no out of memory error. In one device it crashed with less than 100
' For i = 1 To 150 'crashed OOM
' For i = 1 To 120 'crashed OOM
CustomListView1.Add(CreateMyPhotoList(MyList),i)
Next
End Sub
Sub CreateMyPhotoList(l As List) As B4XView
Dim p As B4XView = xui.CreatePanel("carthage") 'carthage is the event name
p.SetLayoutAnimated(0, 0, 0, CustomListView1.AsView.Width, 130dip)
p.LoadLayout("Item") 'has 4 imageviews and 4 Labels as shown in screenshot
Dim iv(4) As B4XView = Array As B4XView(iv1,iv2,iv3,iv4)
Dim lbl(4) As Label=Array As Label(lbl1,lbl2,lbl3, lbl4)
For j=0 To iv.Length-1
Dim f As String=l.Get(Rnd(0,6)) 'random bitmap file
iv(j).SetBitmap(xui.LoadBitmapResize(File.DirAssets, f, iv(j).Width, iv(j).Height, False))
Dim cd As ColorDrawable
cd.Initialize(Colors.RGB(255,255,200),10dip)
lbl(j).Background=cd
lbl(j).Text=f
lbl(j).TextColor=Colors.Black
lbl(j).TextSize=20
lbl(j).Tag=j
Next
Return p
End Sub
Sub CustomListView1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
Dim ExtraSize As Int = 20
For i = 0 To CustomListView1.Size - 1
Dim p As B4XView = CustomListView1.GetPanel(i)
If i > FirstIndex - ExtraSize And i < LastIndex + ExtraSize Then
'visible+
If p.NumberOfViews = 0 Then
p.LoadLayout("item")
Dim iv(4) As B4XView = Array As B4XView(iv1,iv2,iv3,iv4)
Dim lbl(4) As Label=Array As Label(lbl1,lbl2,lbl3, lbl4)
For j=0 To iv.Length-1
Dim f As String=MyList.Get(Rnd(0,6))
iv(j).SetBitmap(xui.LoadBitmapResize(File.DirAssets, f, iv(j).Width, iv(j).Height, False))
Dim cd As ColorDrawable
cd.Initialize(Colors.White,10dip)
lbl(j).Background=cd
lbl(j).Text=f
lbl(j).TextColor=Colors.Black
lbl(j).TextSize=20
Next
End If
Else
If p.NumberOfViews > 0 Then
p.RemoveAllViews
End If
End If
Next
End Sub