Hello everyone,
after some days experimenting, i was not able to solve an obvious trivial problem with lazyloading.
I have a B4X mainpage with a lazy load list of entries. Clicking on one entry goes to another page with the details of this entry.
When i go back to the mainpage, the list scrolls automatically to the highest (0) position. What i need is to open the main list with the clicked position of the list on top (or in the middle) of the screen.
I.a.w. the mainpage should remember the position of the clicked item and open at this position when coming back.
I tried by remembering the FirstIndex in the click event and start clv_layLoad at this index, but i get blank items until the indexed item comes down somewhere.
Thanks for any idea in advance !
Chris
after some days experimenting, i was not able to solve an obvious trivial problem with lazyloading.
I have a B4X mainpage with a lazy load list of entries. Clicking on one entry goes to another page with the details of this entry.
When i go back to the mainpage, the list scrolls automatically to the highest (0) position. What i need is to open the main list with the clicked position of the list on top (or in the middle) of the screen.
I.a.w. the mainpage should remember the position of the clicked item and open at this position when coming back.
I tried by remembering the FirstIndex in the click event and start clv_layLoad at this index, but i get blank items until the indexed item comes down somewhere.
B4X:
Sub clv_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
Dim id, npics, h As Int
Dim id_title, title, datum As String
Dim p As Boolean
Dim pnl As B4XView
' FirstIndex = FIndex ' global <==== this is not working !
' LastIndex = LastIndex + FIndex
' Log("===== visible range changed from "&FirstIndex&" to "&LastIndex)
For Each i As Int In PCLV.VisibleRangeChanged(FirstIndex, LastIndex)
Dim item As CLVItem = clv.GetRawListItem(i)
' Dim pnl As B4XView ' = xui.CreatePanel("")
id_title = item.value.As(String) ' Value is id : title instead of only id (numerical)
id = id_title.SubString2(0, id_title.IndexOf(":"))
title = id_title.Substring(id_title.IndexOf(":")+1)
'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)
' check pictures:
npics = SQL1.ExecQuerySingleResult("SElECT count(*) FROM pictures WHERE entry_id = "& id)
' Log(npics &" pics for entry id = "& id)
If npics > 0 Then ' has pictures - no effect in lazyload !!
h = 240dip ' 240
p = True
Else
h = 120dip ' 120
p = False
End If
pnl = CreateListItem(id, title, datum, p, clv.AsView.Width, h) ' height has no influence !
pnl.Tag = title ' to use in hintrequest
item.Panel.AddView(pnl, 0, 0, pnl.Width, h)
Next
End Sub
Sub clv_ItemClick (Index As Int, Value As Object) ' value is id : title
Dim id_title As String = Value
FIndex = Index ' <==== remember when we come back
Log("---- click on Index "& FIndex)
Log("id_title = "& id_title)
curID = id_title.substring2(0,id_title.indexof(":")) ' global to give to page 2
Log("------ Click item nr "& Index &" id = "& curID)
B4XPages.ShowPage("Page 2") ' ===> open detail page for this item
End Sub
Thanks for any idea in advance !
Chris