Android Question Take 2 second for xCustomListView

Pooya1

Active Member
Licensed User
Hi
I use below code in B4a for show 1000 record (I copy code from forum)
Erel said that it take 250ms for show list
But when i run it,it take 2 seconds
My log is : "Loading cards took: 25010ms" (this value is different between 1900 and 2700)
I have a layout contain one label with name "layout1"

B4X:
Sub FillList2
    Dim bitmaps As List = Array("pexels-photo-446811.jpeg", "pexels-photo-571195.jpeg", _
       "pexels-photo-736212.jpeg", "pexels-photo-592798.jpeg")
    Dim n As Long = DateTime.Now
    For i = 1 To 1000
        Dim content As String = $"Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."$
        Dim cd As CardData
        cd.Initialize
        cd.Title = $"This is item #${i}"$
        cd.Content = content
        
        Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(0, 0, 0, CLV1.AsView.Width, 280dip)
        CLV1.Add(p, cd)
    Next
    Log("Loading cards took: " & (DateTime.Now - n) & "ms")
End Sub

Sub CLV1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    Dim ExtraSize As Int = 20
    For i = Max(0, FirstIndex - ExtraSize) To Min(LastIndex + ExtraSize, CLV1.Size - 1)
        Dim p As B4XView = CLV1.GetPanel(i)
        If p.NumberOfViews = 0 Then
            Dim cd As CardData = CLV1.GetValue(i)
            '**************** this code is similar to the code in CreateItem from the original example
            p.LoadLayout("layout1")
            p.GetView(0).Color    =    Colors.RGB(Rnd(1,255),255,255)
        End If
    Next
End Sub
 

Widget

Well-Known Member
Licensed User
Longtime User
What happens when you replace
p.SetLayoutAnimated(0, 0, 0, CLV1.AsView.Width, 280dip)

with
p.SetLayout(0, 0, CLV1.AsView.Width, 280dip)

Also if you are running in Debug mode I would try Tools > Clean Project before doing any speed tests, or run it in Release mode.
 
Upvote 0

Pooya1

Active Member
Licensed User
What happens when you replace
p.SetLayoutAnimated(0, 0, 0, CLV1.AsView.Width, 280dip)

with
p.SetLayout(0, 0, CLV1.AsView.Width, 280dip)

Also if you are running in Debug mode I would try Tools > Clean Project before doing any speed tests, or run it in Release mode.
I tested in release mode and speed is 300ms now :cool:
 
Upvote 0
Top