I downloaded the PreoptimizedCLV library
Modified some of the code to display long images normally, screenshots are as follows
I wanted to replace these images with GIFs or video sources, so I modified the original code further
I added a list variable Private csvList As List and opened a csv file
Read the URL of the GIF image from the CSV file
I modified part of the code of CustomListView1_VisibleRangeChanged
The image can only display the first 5 URLs of the CSV file, and the following ones cannot be displayed, and when you swipe up and down, it will also report an error exit
Hope someone can help me down, thank you very much
[B4X] PreoptimizedCLV - Lazy loading extension for xCustomListView
This is a cross platform class that extends xCustomListView and makes it "lazier". Lazy loading is explained here: https://www.b4x.com/android/forum/threads/b4x-xui-customlistview-lazy-loading-virtualization.87930/#content and here...
www.b4x.com
I wanted to replace these images with GIFs or video sources, so I modified the original code further
I added a list variable Private csvList As List and opened a csv file
Read the URL of the GIF image from the CSV file
B4X:
Private csvList As List
csvList.Initialize
Dim InputStream1 As InputStream
InputStream1 = File.OpenInput(File.DirInternal, "mycsvfile.csv")
Dim TextReader1 As TextReader
TextReader1.Initialize(InputStream1)
Dim Line As String
Do While TextReader1.Ready = True
Line = TextReader1.ReadLine
Dim Fields() As String
Fields = Regex.Split(",", Line)
Dim level As String = Fields(0)
Dim url As String = Fields(1)
Dim name As String = Fields(2)
Dim image As String = Fields(3)
Dim item As Map
item.Initialize
item.Put("level", level)
item.Put("url", url)
item.Put("name", name)
item.Put("image", image)
csvList.Add(item)
Loop
B4X:
Sub CustomListView1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
For Each i As Int In PCLV.VisibleRangeChanged(FirstIndex, LastIndex)
If i>=LastIndex+1 Then Exit
Dim item As CLVItem = CustomListView1.GetRawListItem(i)
Dim pnl As B4XView = xui.CreatePanel("")
item.Panel.AddView(pnl, 0, 0, item.Panel.Width, item.Panel.Height)
Dim data As MyImageData = item.Value
'Create the item layout
pnl.LoadLayout("item")
Dim itmap As Map
itmap = csvList.Get(i+1)
Dim imgurl As String
imgurl=itmap.Get("image")
pnl.GetView(0).GetView(1).Text = itmap.Get("url")'data.IndexOfFirstImage '+ x
MediaManager.SetMedia(pnl.GetView(0).GetView(0),imgurl)' MediaManager.SetMedia(pnl.GetView(0).GetView(0), $"https://picsum.photos/id/${data.IndexOfFirstImage}/500/100.jpg"$)
Next
'The purpose of this call is to find panels that are no longer in the views tree and cancel any ongoing request that is no longer relevant.
'It also happens automatically from time to time but in this case, as many requests are sent frequently, it is better to force it to trim the cache.
'Note that you need to add HU2_PUBLIC to the build configuration.
MediaManager.TrimMediaCache
End Sub
The image can only display the first 5 URLs of the CSV file, and the following ones cannot be displayed, and when you swipe up and down, it will also report an error exit
Hope someone can help me down, thank you very much
Attachments
Last edited: