Android Question CustomListView running too slow

Kiran Raotole

Active Member
Licensed User
I have same problem again.
my customlistview taking more than 4 min for nearly 1200 records of sqlite
7.12.00 7.16.00

my code is :
B4X:
    cursor = Starter.year.ExecQuery("select * from GL where FBOOK='G001' order by FDESC")
    Dim maccode,desc,place,accode,open,open_type,tot_dr,tot_cr,close,close_type As String
  
    Do While cursor.NextRow
        maccode = cursor.GetString("FACCODE")
        desc     = cursor.GetString("FDESC")
        place     = cursor.GetString("FPLACE")
        accode     = cursor.GetString("FACCODE")
        'open     = Round2(cursor.GetString("FAMT"),2)
        open     = cursor.GetString("FAMT")
        open_type = f1.opening_balance_type(Starter.year,maccode,Starter.ch_date2)
        Log(open)
        tot_dr     = Round2(f1.tot_dr(Starter.year,maccode,Starter.ch_date1,Starter.ch_date2),2)
        tot_cr     = Round2(f1.tot_cr(Starter.year,maccode,Starter.ch_date1,Starter.ch_date2),2)
        close    = Round2(f1.balance_as_on(Starter.year,maccode,Starter.ch_date2),2)
        close_type = f1.opening_balance_type(Starter.year,maccode,Starter.ch_date2)
        Log(desc)

        CustomListView1.Add(Add_row(desc,place,accode,open,open_type, _
                                    tot_dr,tot_cr,close,close_type),accode)
    Loop



Sub Add_row(desc As String,place As String,accode As String, _
            open As String,open_type As String,tot_dr As String, _
            tot_cr As String,close As String,close_type As String) As B4XView
    Dim xui As XUI
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0,0,0,60%x,35%x)
    p.LoadLayout("m4741_listview")
    Label1 .Text = desc
    Label2 .Text = place
    Label3 .Text = accode
    Label8 .Text = open
    Label9 .Text = tot_dr
    Label10.Text = tot_cr
    Label11.Text = close
    Label12.Text = open_type
    Label13.Text = close_type
  
    Return p
  
End Sub
whats wrong?
 
Last edited:

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I have same problem again.
my customlistview taking more than 4 min for nearly 1200 records of sqlite
7.12.00 7.16.00

my code is :
B4X:
    cursor = Starter.year.ExecQuery("select * from GL where FBOOK='G001' order by FDESC")
    Dim maccode,desc,place,accode,open,open_type,tot_dr,tot_cr,close,close_type As String
 
    Do While cursor.NextRow
        maccode = cursor.GetString("FACCODE")
        desc     = cursor.GetString("FDESC")
        place     = cursor.GetString("FPLACE")
        accode     = cursor.GetString("FACCODE")
        'open     = Round2(cursor.GetString("FAMT"),2)
        open     = cursor.GetString("FAMT")
        open_type = f1.opening_balance_type(Starter.year,maccode,Starter.ch_date2)
        Log(open)
        tot_dr     = Round2(f1.tot_dr(Starter.year,maccode,Starter.ch_date1,Starter.ch_date2),2)
        tot_cr     = Round2(f1.tot_cr(Starter.year,maccode,Starter.ch_date1,Starter.ch_date2),2)
        close    = Round2(f1.balance_as_on(Starter.year,maccode,Starter.ch_date2),2)
        close_type = f1.opening_balance_type(Starter.year,maccode,Starter.ch_date2)
        Log(desc)

        CustomListView1.Add(Add_row(desc,place,accode,open,open_type, _
                                    tot_dr,tot_cr,close,close_type),accode)
    Loop



Sub Add_row(desc As String,place As String,accode As String, _
            open As String,open_type As String,tot_dr As String, _
            tot_cr As String,close As String,close_type As String) As B4XView
    Dim xui As XUI
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0,0,0,60%x,35%x)
    p.LoadLayout("m4741_listview")
    Label1 .Text = desc
    Label2 .Text = place
    Label3 .Text = accode
    Label8 .Text = open
    Label9 .Text = tot_dr
    Label10.Text = tot_cr
    Label11.Text = close
    Label12.Text = open_type
    Label13.Text = close_type
 
    Return p
 
End Sub
whats wrong?

How long does it take if you use a TableView instead of your custom listview?

RBS
 
Upvote 0

Kiran Raotole

Active Member
Licensed User
I have same problem again.
my customlistview taking more than 4 min for nearly 1200 records of sqlite
7.12.00 7.16.00

my code is :
B4X:
    cursor = Starter.year.ExecQuery("select * from GL where FBOOK='G001' order by FDESC")
    Dim maccode,desc,place,accode,open,open_type,tot_dr,tot_cr,close,close_type As String
 
    Do While cursor.NextRow
        maccode = cursor.GetString("FACCODE")
        desc     = cursor.GetString("FDESC")
        place     = cursor.GetString("FPLACE")
        accode     = cursor.GetString("FACCODE")
        'open     = Round2(cursor.GetString("FAMT"),2)
        open     = cursor.GetString("FAMT")
        open_type = f1.opening_balance_type(Starter.year,maccode,Starter.ch_date2)
        Log(open)
        tot_dr     = Round2(f1.tot_dr(Starter.year,maccode,Starter.ch_date1,Starter.ch_date2),2)
        tot_cr     = Round2(f1.tot_cr(Starter.year,maccode,Starter.ch_date1,Starter.ch_date2),2)
        close    = Round2(f1.balance_as_on(Starter.year,maccode,Starter.ch_date2),2)
        close_type = f1.opening_balance_type(Starter.year,maccode,Starter.ch_date2)
        Log(desc)

        CustomListView1.Add(Add_row(desc,place,accode,open,open_type, _
                                    tot_dr,tot_cr,close,close_type),accode)
    Loop



Sub Add_row(desc As String,place As String,accode As String, _
            open As String,open_type As String,tot_dr As String, _
            tot_cr As String,close As String,close_type As String) As B4XView
    Dim xui As XUI
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0,0,0,60%x,35%x)
    p.LoadLayout("m4741_listview")
    Label1 .Text = desc
    Label2 .Text = place
    Label3 .Text = accode
    Label8 .Text = open
    Label9 .Text = tot_dr
    Label10.Text = tot_cr
    Label11.Text = close
    Label12.Text = open_type
    Label13.Text = close_type
 
    Return p
 
End Sub
whats wrong?

Is something wrong in my code which make it slow?
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
1200 records is absolutely nothing and as long as you're not loading any large images then I would say that 1200 records should only take about 1.2 seconds without lazy loading, (my basic calculations without images is 1/10 of a second equals about 100 records populated).

Can you upload an small example of your project so that we can try it for ourselves, 4 minutes is just too lonf?
 
Upvote 0
D

Deleted member 103

Guest
Are you testing it in release mode?


Wrong advice. You should use lazy loading instead.
That's absolutely not wrong!

A test with 100 entries:
With loadlayout End-Time= 9808
Without loadlayout End-Time= 2606

test.png
 
Upvote 0
D

Deleted member 103

Guest
How does I use without loadlayout.
Here's an example:
You can extend the sub with even more views.

B4X:
Sub
Add_row(Text As String, Width As Int, Height As Int) As Panel
    Dim pnl As Panel
    Dim lbl As Label
    Dim btnSent,btnDelet As Button

    pnl.Initialize("")
    pnl.Color = Colors.White
    
    btnSent.Initialize("btnSent")
    btnSent.Typeface = Typeface.MATERIALICONS
    btnSent.Text = Chr(0xE163)
    btnSent.TextSize = 20
    
    btnDelet.Initialize("btnDel")
    btnDelet.Typeface = Typeface.FONTAWESOME
    btnDelet.Text = Chr(0xF014)
    btnDelet.TextSize = 20
    
    lbl.Initialize("")
    lbl.Typeface = Typeface.DEFAULT
    lbl.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
    lbl.Text = Text
    lbl.TextSize = 16
    lbl.TextColor = Colors.Black

    pnl.AddView(lbl, 5dip, 2dip, Width - (90dip + Height), Height - 4dip) 'view #0
    pnl.AddView(btnSent, Width - (80dip + Height), 5dip, 70dip, Height - 10dip) 'view #1
    pnl.AddView(btnDelet, Width - (Height + 5dip), 5dip, Height - 5dip, Height - 10dip) 'view #1
    Return pnl
End Sub
 
Upvote 0
Top