Android Question Slow CustomListView because of inside Table

AHilberink

Active Member
Licensed User
Longtime User
Hi,

I need to speed up my CustomListView.

This is the code of the ListView:
B4X:
Sub OpdrachtOverzicht(row As Int)
    Log(1&"-"&DateTime.Time(DateTime.Now))
    OpdrachtIDList.Clear
    OpdrachtTable.Clear
    OpdrachtTable.AsView.Visible=True
   
    Main.SQL1.BeginTransaction

    Dim Query As String = "SELECT ROWID, Ingetrokken, Berichtnummer, Naam, Begintijd, Opdracht, Bewaart, Toelichting FROM "&Main.DBOpdrachten&" WHERE Begindatum='"&DisplayDatum&"' AND Eindeuitvoering='' ORDER BY Begintijd"
    Dim res As ResultSet = Main.SQL1.ExecQuery(Query)
   
    DBUtils.EmptyTable(Main.SQL1,"DumpTabel")
    Do While res.NextRow
        If(res.Getstring("Ingetrokken")="1" And Starter.IngetrokkenZichtbaar=False) Then
        Else
            EigenFuncties.Aanvulling(res.GetInt("Berichtnummer"))
        End If
    Loop

    If(lstToelichting.IsInitialized=False) Then lstToelichting.Initialize
    lstToelichting.Clear
    res.Position=-1
    Do While res.NextRow
        If(res.Getstring("Ingetrokken")="1" And Starter.IngetrokkenZichtbaar=False) Then
        Else
            If(res.Position=3) Then
                ProgressDialogShow("Laden")
                Sleep(0)
            End If
            OpdrachtIDList.Add(res.GetInt("ROWID"))
            Dim p As B4XView = CreateItem(res.GetInt("Berichtnummer"),res.GetString("Ingetrokken"), res.GetString("Naam"),res.GetString("Begintijd"),res.GetString("Opdracht"),res.GetString("Bewaart"),res.GetString("Toelichting"))
            OpdrachtTable.Add(p, expandable.CreateValue(p, "some value"))
            If(res.Getstring("Ingetrokken")<>"1") Then expandable.ToggleItem(OpdrachtTable.Size-1)
            lstToelichting.Add(res.GetString("Toelichting"))
        End If
    Loop
    If(res.RowCount>0) Then
        OpdrachtTable.JumpToItem(row)
        ProgressDialogHide
    End If
    res.Close
    Main.SQL1.EndTransaction
    Log(2&"-"&DateTime.Time(DateTime.Now))
End Sub

This is the part of CreateItem:
B4X:
Sub CreateItem(Bericht As Int, Ingetrokken As Int, Klantnaam As String, Tijd As String, Omschrijving As String, Reeds As String, Toelichting As String) As B4XView
    Dim p As B4XView = xui.CreatePanel("")

    'EigenFuncties.Aanvulling(Bericht)
    Dim Rows As Int=Main.SQL1.ExecQuerySingleResult("SELECT COUNT(*) FROM Dumptabel WHERE Berichtnummer="&Bericht)

    p.SetLayoutAnimated(0, 0, 0, OpdrachtTable.AsView.Width, tblAanvulling1.RowHeight*Rows+tblAanvulling1.HeaderHeight+HeaderHoogte+NaamHoogte)
    p.Height=tblAanvulling1.RowHeight*Rows+tblAanvulling1.HeaderHeight+HeaderHoogte+NaamHoogte
    p.Width=OpdrachtTable.AsView.Width
    p.LoadLayout("Item")
    p.SetLayoutAnimated(0, 0, 0, p.Width, p.GetView(0).Height) 'resize it to the collapsed height

    'Log("1A"&"-"&DateTime.Time(DateTime.Now))

    HeaderHoogte=p.GetView(0).Height
    NaamHoogte=lblKlantNaam.Height
   
    lblKlantNaam.Text=Klantnaam
    lblTijd1.Text=Tijd
    lblOmschrijving1.Text=Omschrijving
    If(Toelichting<>"" And Toelichting<>Null) Then
        btnSpeak.Visible=True
    Else
        btnSpeak.Visible=False
    End If

    If(Reeds=1) Then
        lblReeds1.Visible=True
    Else
        lblReeds1.Visible=False
    End If

    If(OpdrachtTable.Size Mod 2 = 0) Then
        pnlTitle.Color = Colors.White
    Else
        pnlTitle.Color = EigenFuncties.HexToColor("#FFF0FFFF")
    End If
    pnlExpanded.Color = ShadeColor(Colors.White)

    'Log("1B"&"-"&DateTime.Time(DateTime.Now))
    If (Ingetrokken=1 )Then
        Dim rs As RichString
        rs.Initialize(lblOmschrijving1.Text)
        rs.Strikethrough(0,rs.Length)
        lblOmschrijving1.Text=rs
        lblOmschrijving1.TextColor=Colors.Red

        rs.Initialize(lblTijd1.Text)
        rs.Strikethrough(0,rs.Length)
        lblTijd1.Text=rs
        lblTijd1.TextColor=Colors.Red
       
        rs.Initialize(lblReeds1.Text)
        rs.Strikethrough(0,rs.Length)
        lblReeds1.Text=rs
        lblReeds1.TextColor=Colors.Red
    End If

    If(Bericht<>0) Then
        'Log("1C"&"-"&DateTime.Time(DateTime.Now))
        tblAanvulling1.Height=tblAanvulling1.RowHeight*Rows+tblAanvulling1.HeaderHeight
        tblAanvulling1.ClearAll
        tblAanvulling1.LoadSQLiteDB(Main.SQL1,"SELECT Actie, Omschrijving, Aantal FROM DumpTabel WHERE Berichtnummer="&Bericht,False)
        tblAanvulling1.SetColumnsWidths(Array As Int(90dip,tblAanvulling1.Width-145dip,55dip))
        tblAanvulling1.SetCellAlignments(Array As Int(Gravity.LEFT,Gravity.LEFT,Gravity.CENTER))
        tblAanvulling1.SetHeaderAlignments(Array As Int(Gravity.LEFT,Gravity.LEFT,Gravity.CENTER))
    End If

    'Log("1D"&"-"&DateTime.Time(DateTime.Now))
    EigenFuncties.ResetUserFontScale(p)
    'Log("1E"&"-"&DateTime.Time(DateTime.Now))
   
    Return p
End Sub

This part seems to take some time:
B4X:
tblAanvulling1.LoadSQLiteDB(Main.SQL1,"SELECT Actie, Omschrijving, Aantal FROM DumpTabel WHERE Berichtnummer="&Bericht,False)

Main:
B4X:
Dim SQL1 As SQLCipher

This is slow from 10 lines and more.
Is there a way to speed this up? Can I optimize my code?

Kind regards,
André
 

klaus

Expert
Licensed User
Longtime User
Sorry, but I do not understand what exactly you want to do.
Are you trying to add a Table in each item in the CustomListView.

What is this supposed to do ?
tblAanvulling1.LoadSQLiteDB(Main.SQL1,"SELECT Actie, Omschrijving, Aantal FROM DumpTabel WHERE Berichtnummer="&Bericht,False)
 
Last edited:
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
Sorry, but I do not understand what exactly you want to do.
Are you trying to a Table in each item in the CustomListView.

What is this supposed to do ?

Hi Klaus,

Thank you for your reply. Yes, I need a table on every item in the CustomLostView. Loading this table seems to extremly slow down the loading.

This table is a summary of the item.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I am afraid that you will get trouble with this.
The Table object is basically a ScrollView.
This means several ScrollViews in another ScrollView.
The scrolling of the whole could be problematic.
How many rows are in the Tables ?
The Table object is a huge one.
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
I am afraid that you will get trouble with this.
The Table object is basically a ScrollView.
This means several ScrollViews in another ScrollView.
The scrolling of the whole could be problematic.
How many rows are in the Tables ?
The Table object is a huge one.

Hi Klaus,

I am using it for more than a year without trouble. The only thing is loading time. I am loading from a SQL database.
The CustomListView has 30 items and each item can have 2 lines within its table.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Did you change something that makes slower now ?
It is impossible for me give a concrete advice with just some code snippets.
It need a deeper look to find where the bottleneck is.
With two lines per table I am sure that the are simpler solutions.
Are the number of columns always the same ?
Do you need scrolling ?
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
Did you change something that makes slower now ?
It is impossible for me give a concrete advice with just some code snippets.
It need a deeper look to find where the bottleneck is.
With two lines per table I am sure that the are simpler solutions.
Are the number of columns always the same ?
Do you need scrolling ?
Hello Klaus.

Thanks for your support.

Did you change something that makes slower now? The problem exist from the beginning, but at the beginning there were only 10 lines, now there are 30 and more.
It is impossible for me give a concrete advice with just some code snippets. I will made a sample project instead of snippets.
It need a deeper look to find where the bottleneck is. Example with data so you will see what is happening.
Are the number of columns always the same? Yes, they are
Do you need scrolling? Yes, I need this

Give me a day of two to work this example out. It is a big project and I need to cut this into a small example.
 
Upvote 0
Top