Android Question CustomListView running too slow

Discussion in 'Android Questions' started by Kiran Raotole, Aug 10, 2018.

  1. Kiran Raotole

    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 :
    Code:
    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 StringAs 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: Aug 10, 2018
  2. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

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

    RBS
     
  3. 1lusca

    1lusca Member Licensed User

    Maybe you can take a look at this
     
  4. Kiran Raotole

    Kiran Raotole Active Member Licensed User

    Is something wrong in my code which make it slow?
     
  5. Filippo

    Filippo Expert Licensed User

    the function loadlayout is too slow. :(
    Make your panel always in real time, your code will be a little bit longer but many faster. :)
     
  6. Peter Simpson

    Peter Simpson Expert Licensed 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?
     
    Mahares likes this.
  7. Erel

    Erel Administrator Staff Member Licensed User

    Are you testing it in release mode?

    Wrong advice. You should use lazy loading instead.
     
  8. Filippo

    Filippo Expert Licensed User

    That's absolutely not wrong!

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

    test.png
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    2.6 seconds is also not fast enough. The correct solution is to use lazy loading. This way you will only create ~5 items and it will be fast.
     
  10. Kiran Raotole

    Kiran Raotole Active Member Licensed User

    I have to show all record in listview.

    How does I use without loadlayout.
     
  11. Filippo

    Filippo Expert Licensed User

    Here's an example:
    You can extend the sub with even more views.

    Code:
    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, 
    5dip2dip, Width - (90dip + Height), Height - 4dip'view #0
        pnl.AddView(btnSent, Width - (80dip + Height), 5dip70dip, Height - 10dip'view #1
        pnl.AddView(btnDelet, Width - (Height + 5dip), 5dip, Height - 5dip, Height - 10dip'view #1
        Return pnl
    End Sub
     
  12. Arthur Ávila

    Arthur Ávila Member Licensed User

    Maybe this example with lazy loading can help you, just need to be adapted.
     

    Attached Files:

    Mahares likes this.
  13. Erel

    Erel Administrator Staff Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice