Android Question Cannot CLV.JumpToItem before ShowPage

Ilya G.

Active Member
Licensed User
Longtime User
I want to show the page when all items are loaded into the CLV to avoid the list flickering, but in this case CLV.JumpToItem doesn't work. Is that normal or its a bug?

B4XMainPage:
HomePage.Initialize
B4XPages.AddPage("Home", HomePage)

ChatPage.Initialize
B4XPages.AddPageAndCreate("Chat", ChatPage)
HomePage:
Sub CustomListView1_ItemClick (Index As Int, Value As Object)
    B4XPages.MainPage.ChatPage.UpdateMessages(Value)
End Sub
ChatPage:
Sub UpdateMessages (m As Map)
    CustomListView1.Clear
'    CustomListView1.sv.ScrollViewOffsetY = 0
    
    Private Cursor As Cursor = Starter.SQL.ExecQuery("")
    Private Value As Map

    For i = 0 To Cursor.RowCount - 1
        Cursor.Position = i
        Value.Initialize

        For c = 0 To Cursor.ColumnCount - 1
            Value.Put(Cursor.GetColumnName(c), Cursor.GetString2(c))
        Next
        
        Private label As Label
        label.Initialize("")
        label.TextSize = 15
        label.SetLayoutAnimated(0, 0, 0, CustomListView1.AsView.Width - 100dip, 20dip)
        
        Private holder As B4XView = XUI.CreatePanel("")
        holder.SetLayoutAnimated(0, 0, 0, CustomListView1.AsView.Width, 40dip + Max(20dip, SU.MeasureMultilineTextHeight(label, Cursor.GetString("message"))) + 15dip)

        CustomListView1.Add(holder, Value)
    Next
    Cursor.Close

    If CustomListView1.Size > 0 Then
        Sleep(0)
        CustomListView1.JumpToItem(CustomListView1.Size - 1)
        CustomListView1.Refresh
    End If
    
    B4XPages.ShowPage("Chat")
End Sub
 

LucaMs

Expert
Licensed User
Longtime User
(however I don't know why it doesn't work your way)
I didn't notice that there is also the CustomListView1_VisibleRangeChanged event-routine; this is what gives problems with the jump.

I want to show the page when all items are loaded into the CLV to avoid the list flickering:
To do that you must...
B4X:
Sub UpdateMessages As ResumableSub
' ...
    Return True ' It doesn't matter if True or False.
End Sub

B4X:
Wait For (ChatPage.UpdateMessages) Complete(Unused As Boolean)
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
I want to show the page when all items are loaded into the CLV to avoid the list flickering:
You can also place a panel over the CLV and with ".SetVisibleAnimated(250,False)" you smoothly hide it when the list is loaded, then the user has a nice smooth transition. I use this trick in some customviews where I have the CLV in use to avoid exactly this problem.
 
Upvote 0

Ilya G.

Active Member
Licensed User
Longtime User
I tried, but it seemed to me that the inconvenience is more than the benefits
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Move B4XPages.ShowPage("Chat") to B4XMainPage , CLV.JumpToItem works fine,see below



B4XMainPage

Private Sub Button1_Click
B4XPages.ShowPage("Chat") '<= It should be showed first
ChatPage.UpdateMessages
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…