B4J Question xCustomListView lazy loading - What is the nature of this behaviour?

hatzisn

Expert
Licensed User
Longtime User
Hi everyone,

Please download the B4J project, run it and try the following looking at the same time in the logs window:
1) First in the Vertical seek bar try to press continuesly the down arrow looking at the logs. You will notice that you are traversing the same part of the records as it is returning back.
2) Then try to move the seek bar by clicking on the free area of the seekbar. The same thing happens.
3) Then try to move the seek bar by grabbing the cursor - this works

Am I doing something wrong?
 

Attachments

  • XCustomListViewLazyLoading.zip
    109.6 KB · Views: 155

hatzisn

Expert
Licensed User
Longtime User
My mistake. Corrected with the following code:

B4X:
Sub xclv_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    Dim ExtraSize As Int = 10
    Log(FirstIndex & "," & LastIndex)
    For ii = Max (0, FirstIndex - ExtraSize) To Min(LastIndex + ExtraSize, xclv.Size - 1)
        Dim p As B4XView
        p = xclv.GetPanel(ii)
        If ii >= FirstIndex - ExtraSize And ii <= LastIndex + ExtraSize Then
            If p.NumberOfViews = 0 Then
                p.LoadLayout("2")
                Dim btn As Button = p.GetView(0).GetView(2)
                Dim img As ImageView = p.GetView(0).GetView(0)
                
                
                
                Dim crd As Cards
                crd.Initialize
                crd = xclv.GetValue(ii)
                btn.Text = crd.text
                
                img.SetImage(xui.LoadBitmap(File.DirAssets, crd.Image))
            End If
        Else
            If p.NumberOfViews > 0 Then
                p.RemoveAllViews
            End If
        End If
    Next
End Sub
 
Upvote 0
Top