Android Question Custom list needs long time to load.

TheRealMatze

Active Member
Licensed User
Hello there,
i have a little optical problem with a custom list. When i move between pages i want to load data from a sqlite db. In this testcase about 2k rows.
B4X:
Sub refreshList(ID As String)
    Dim dbRows As ResultSet = database.getAll(ID)

    Activity.RemoveAllViews
    Activity.LoadLayout("list")
    loading.Visible=True            'loading label on the page
    Log("begin slowness")
    For farmNum = 0 To dbRows.RowCount-1
        dbRows.NextRow
        Dim fi As viewValue
        fi.lbl1 =dbRows.GetString("na")
        fi.lbl2 =dbRows.GetString("bi")
        fi.lbl3 ="..."
        fi.lbl4 ="..."
        clv1.Add(createItem(fi),dbRows.GetString("id"))
    Next
    loading.Visible=False
    Log("due")
End Sub

private Sub createItem(t As viewValue) As B4XView
    Dim p As B4XView=xui.createpanel("")
    p.SetLayoutAnimated(0,0,0,100%x,140dip)
    p.SetColorAndBorder(Colors.Transparent,Colors.Transparent,Colors.Transparent,Colors.Transparent)
    p.LoadLayout("item")
    lbl1.text=t.lbl1
    lbl2.text=t.lbl2
    lbl3.text=t.lbl3
    lbl4.text=t.lbl4
    Return p
End Sub

It works technically, but i need ~5 seconds for this operation. While this i see a blank screen, not ideal... When i insert a sleep(0) before the "next" it looks nice, but it takes forever (ten times the normal speed). So, that is not an option. How can i optimize it to look better?
Currently i never see my loading-label, because it´s locking until all items are ready. My first idea was to create a activity only with a loading-bar and reload the rest with a timer. Works... but is not nice. A single sleep before the loop also will not help, i see a blank page without the static header and the loading-info from "list".

I´ve seen "lazy loading" infos, but it looks very complicated and i dont know if this is what i search for to solve it.
Typically i have to load 100-500 items, but it can go up to 5k.

Thanks!
Matze
 

MicroDrie

Well-Known Member
Licensed User
Longtime User
The question here is what's slow now? Because how many records can you display at the same time? If that's a limited number, why are you getting all the records at once? All those loaded records must be stored in memory. If the memory threatens to become full, the OS, or app could start a space making process, with slowness as a result. It may be useful, if necessary with an extra field, to retrieve only a series of records at a time to save memory space.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I´ve seen "lazy loading" infos, but it looks very complicated and i dont know if this is what i search for to solve it.
As Andrew and Marco mentioned above, 'LazyLoading' is the way to go. If you can include your SQLite database if not confidential or one with fake similar data and also include your item layout, If the database is too big attach one with fewer rows. I am pretty sure you will get help. Members are generous with their time and knowledge. Do not include your project, because based on your code you posted in post #1, you are not taking the correct approach.
 
Upvote 0

TheRealMatze

Active Member
Licensed User
Thanks for the response.
Perfect solution @Andrew (Digitwell). That works as i want, absolutely perfect without any overhead. The "PreoptimizedCLV" did not work, or i´m to stupid. I got empty fields and when i scroll down it crashes after 13 entrys. But the first solution works so good, i use it.

The question here is what's slow now? Because how many records can you display at the same time?
Good point @MicroDrie. I see slowness when more than 250 entrys. The theroretical maximum is in the area 5-10k - but most of the users have <1000 entrys. There is no binary stuff inside, only plain text. The filled data is about 100 chars. I don´t think it´s too much data, or am i wrong?
 
Upvote 0
Top