Android Question Lazy Loading with preoptimized clv - strange error (?)

Phayao

Active Member
Licensed User
Longtime User
Hello,

the preoptimized lazy loading works fine for me in all examples - but in my case there is a strange effect.
When i first open the mainpage with the clv it doesnt show anything, but when i come back to the mainpage from another page, it shows the items.
I initialize in B4XMainPage:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Log("----- mainpage created")
    Root.LoadLayout("main1")
...
    PCLV.Initialize(Me, "PCLV", clv)
end sub

Sub B4XPage_Appear
    Log("------- mainpage APPEAR start")
    Main.sIDLastPageName = "MainPage"
 
    ' ---- time span - at start its the whole span:
    Dim q As String
    q = "SELECT datum FROM entries ORDER BY substr(datum,0,4) || substr(datum,5,7) || substr(datum,8,10) ASC LIMIT 1"
    dstart = SQL1.ExecQuerySingleResult(q)
    If kvs.Get("dstart").As(String).length > 9 Then    _    ' saved dstart is ok !
        dstart = kvs.GetDefault("dstart", dstart)
    lblStart.Text = func.formatDate(dstart)

    q = "SELECT max(datum) FROM entries" '  ORDER BY substr(datum,0,4) || substr(datum,5,7) || substr(datum,8,10) DESC LIMIT 1"
    dend = SQL1.ExecQuerySingleResult(q)
    lblEnd.Text = func.formatDate(dend)
    Log("APPEAR create dstart= "& dstart &" dend "& dend)
    DateTime.DateFormat = "yyyy-MM-dd"
    If  DateTime.DateParse(dstart) >  DateTime.DateParse(dend) Then
        MsgboxAsync("End date "& dend &" should be later than start date "& dstart,"ERROR")
        Return
    End If
    q = $" SELECT entry_id, title, datum FROM entries
            WHERE datum BETWEEN "${dstart}" AND "${dend}"
            ORDER BY substr(datum,1,4) || substr(datum,6,2) || substr(datum,9,2) || entry_id DESC "$
    lazyload(q)        '  new date range
 
end sub

Sub lazyload(q As String)
    Dim rs As ResultSet
    Dim id As Int
    rs = SQL1.ExecQuery(q)
    Nmax = rs.RowCount - 1        ' not display more rows than this
    Log("lazyload query nrow= "& Nmax)
    clv.clear     '<=== makes no difference
    Do While rs.NextRow
        id = rs.GetInt("entry_id")
        PCLV.AddItem(200dip, xui.Color_white, id)
    Loop
    PCLV.Commit
End Sub

Sub clv_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    Dim id, npics, h As Int
    Dim title, datum As String
    Dim p As Boolean
    Log("===== visible range changed from "&FirstIndex&" to "&LastIndex)
    If LastIndex >= Nmax Then LastIndex = Nmax
    For Each i As Int In PCLV.VisibleRangeChanged(FirstIndex, LastIndex)
        Dim item As CLVItem = clv.GetRawListItem(i)
        Dim pnl As B4XView  = xui.CreatePanel("")
    
        id = item.value
        title = SQL1.ExecQuerySingleResult("SElECT title FROM entries WHERE entry_id= "& id)
        datum =  SQL1.ExecQuerySingleResult("SElECT datum FROM entries WHERE entry_id= "& id)
        Log("row "& i &" id= "&id&" title= "&title)

        pnl = CreateListItem(id, title, datum, clv.AsView.Width, 160dip)
        item.Panel.AddView(pnl, 0, 0, item.Panel.Width, item.Panel.Height)
        Log("finish createlistitem id= "&id)
    Next

' fill items in each panel:
Sub CreateListItem(id As Int, title As String, dat As String, w As Int, h As Int) As Panel
    Dim pnl As B4XView = xui.CreatePanel("")
        ' Log("createlistitem id="&id)
    Dim rs As ResultSet
    Dim q, pic As String
    Dim left As Int

    pnl.SetLayoutAnimated(0, 0, 0, w, h)
    pnl.LoadLayout("itemlayout4")

    lblTitle.Text = title
    lblTime.Text = formatDate(dat)
 
    Return pnl
End Sub

The layout "itemlayout4" has transparent background.
The log shows that the "empty" list calls the clv_visiblerangechanged but nothing can be seen...

After 2 days experimenting, I hope someone can spot the problem :)
Highly appreciated - Thanks,

Chris

===== I found the simple reason:
The layout of "main1" has an invisible panel for a splashscreen that covers the whole customlistview !
So even it is set to invisible and is behind the clv, it disturbs the lazyload list !!
 
Last edited:
Top