I am creating a CustomListView "allclv" with a nested CustomListView "clvPhoto". In each clvPhoto I add 30 photos stored in DirInternal. This display of 5 of these CustomListView takes more than 20s, which is very long.
I tried using PreoptimizedCLV, but I understand how to use it correctly.
What am I doing wrong? Should I use a separate PreoptimizedCLV for each of my clvPhotos? Or one PreoptimizedCLV for all clvPhotos?
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
For i=0 To 5
allclv.Add(CreatePhoto(i),"")
clvPhoto.AsView.Tag = clvPhoto
Dim templist As List
templist=File.ListFiles(File.DirInternal)
For j=0 To templist.Size-1
AddPhoto(templist.Get(j),i)
Next
Next
End Sub
Sub AddPhoto (Name As String, index As Int)
If Name.Contains(".jpg") Then
Dim pnl As B4XView = allclv.GetPanel(index)
Dim clv As CustomListView = pnl.GetView(1).Tag
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, clvPhoto.AsView.Width/4, clvPhoto.AsView.Height)
p.LoadLayout("iv")
FillImageToView(xui.LoadBitmapResize(File.DirInternal, Name, clvPhoto.AsView.Width/4, clvPhoto.AsView.Height, True),iv)
clv.Add(p,"")
End If
End Sub
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
For i=0 To 5
allclv.Add(CreatePhoto(i),"")
clvPhoto.AsView.Tag = clvPhoto
PCLV.Initialize(Me, "PCLV", clvPhoto)
Dim templist As List
templist=File.ListFiles(File.DirInternal)
For j=0 To templist.Size-1
AddPhoto(templist.Get(j))
Next
Next
PCLV.Commit
End Sub
Sub AddPhoto (Name As String)
If Name.Contains(".jpg") Then
PCLV.AddItem(100dip, xui.Color_White, Name)
End If
End Sub
Sub clvPhoto_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
For Each i As Int In PCLV.VisibleRangeChanged(FirstIndex, LastIndex)
Dim item As CLVItem = clvPhoto.GetRawListItem(i)
Dim pnl As B4XView = allclv.GetPanel(i)
Dim clv As CustomListView = pnl.GetView(1).Tag
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, clvPhoto.AsView.Width/4, clvPhoto.AsView.Height)
p.LoadLayout("iv")
FillImageToView(xui.LoadBitmapResize(File.DirInternal, item, clvPhoto.AsView.Width/4, clvPhoto.AsView.Height, True),iv)
clv.Add(p,"")
Next
End Sub
What am I doing wrong? Should I use a separate PreoptimizedCLV for each of my clvPhotos? Or one PreoptimizedCLV for all clvPhotos?