Android Question xCustomListView with 10000 items LAG

Douglas Farias

Expert
Licensed User
Longtime User
Hi All.
I m folowing the @Erel example of xClv with a lot of items

https://www.b4x.com/android/forum/threads/b4x-xui-customlistview-lazy-loading-virtualization.87930/

but i have a problem, i m geting a LAG when i move the scroll to down or to top.
I'd like to know if I'm doing something wrong in my code.

this sub is what i m using to add 10000 itens on clv.
B4X:
Sub Carrega_PedidosEnviados
    scConteudoPrincipal.Panel.RemoveAllViews
    scConteudoPrincipal.Panel.Height = 100%y
    scConteudoPrincipal.Panel.LoadLayout("pedidosEnviados")
    pFundoPrincipal.Height = 100%y
    scConteudoPrincipal.Panel.Height = pFundoPrincipal.Height
    lbTituloActionBar.Text = "PEDIDOS ENVIADOS"

    For i = 1 To 10000
        Dim cd As  DataClvPedidosEnviados
        cd.Initialize
        cd.titulo = "Farol direito Palio Weekend 2010"
        cd.desc = "Farol lado do passageiro da Palio Weekend ELX..."
        cd.numeroPedido = "Pedido: 10536"
        cd.hora = "25/02/2018 15:35"
      
        If i Mod 2 == 0 Then
            cd.cor = 0xFFafafaf
        Else
            cd.cor = 0xFF8b8b8b
        End If
      
        Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(0, 0, 0, clvPedidosEnviados.AsView.Width, 15%y)
        clvPedidosEnviados.Add(p, cd)
    Next

  
    pPrincipal.Visible = True
  
  
  
End Sub



and here is my VisibleRangeChanged sub

B4X:
Sub clvPedidosEnviados_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    Dim ExtraSize As Int = 5
    For i = 0 To clvPedidosEnviados.Size - 1
        Dim p As B4XView = clvPedidosEnviados.GetPanel(i)
        If i > FirstIndex - ExtraSize And i < LastIndex + ExtraSize Then
            'visible+
            If p.NumberOfViews = 0 Then
                Dim cd As DataClvPedidosEnviados = clvPedidosEnviados.GetValue(i)
                p.LoadLayout("clvPedidosEnviados")
      
                Private cs As CSBuilder
                cs.Initialize
                cs.Bold.Size(13).Append(cd.titulo).Append(CRLF).PopAll
                cs.VerticalAlign(3dip)
                cs.Append(cd.desc).PopAll
                lbDescPedidoClvPedidosEnviados.Text = cs
  
                If i Mod 2 == 0 Then
                    pClaroClvPedidosEnviados.Color = cd.cor
                    lbDescPedidoClvPedidosEnviados.Color = cd.cor
                Else
                    pClaroClvPedidosEnviados.Color = 0xFF8b8b8b
                    lbDescPedidoClvPedidosEnviados.Color = cd.cor
                End If
              
              
            End If
        Else
            'not visible
            If p.NumberOfViews > 0 Then
                p.RemoveAllViews
            End If
        End If
    Next
End Sub

B4X:
Type DataClvPedidosEnviados (titulo As String, desc As String, numeroPedido As String ,hora As String, cor As Int)


Is there a problem with my code? I tried to review and redo but the lag continues.
on my list there are no pictures.

obs: the lag occurs in debug and release too.

here is my layout "pedidosEnviados", dont have images, only 3 labels and 2 panels.
1.png


how can i make a clv suport 10.000 items or more with no lag?

thx all
 
Last edited:

Douglas Farias

Expert
Licensed User
Longtime User
Are you testing it in release mode?

Can you create a small project with only the list and upload it?

Release or debug the lag is the same here.

here is the example project

My device is the Samsung S7 Edge (Android 7.0)
E:\Android\platforms\android-27\android.jar
C:\Program Files\Java\jdk1.8.0_121\bin\javac.exe

THX
 

Attachments

  • Simular Lista.zip
    249.4 KB · Views: 253
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should use File - Export as zip when uploading projects.

I've made some improvements and it scrolls smoother:
1. Disable the layout animation.
2. Use anchors instead of designer script where possible.
3. Reuse the same layout instead of loading a new layout each item.
 

Attachments

  • CLV.zip
    31 KB · Views: 275
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
My code did improve the performance. You can see the time it spends in the VisibleRangeChanged event.
I don't think that you will be able to improve it more.

Why load so many items? The user will never go over 10,000 items. You can use the ReachEnd event to add more items.
 
Upvote 0
Top