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
 

Ilya G.

Active Member
Licensed User
Longtime User
Unfortunately, when you open the window, the first messages are visible for a few moments.

SCR_20220529_120659_001 (1).gif
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You are seeing the behavior of the native ScrollView.

I don't get any flicker with this change:
B4X:
    B4XPages.ShowPage("Chat")
    If CustomListView1.Size > 0 Then
        Sleep(0)
        CustomListView1.JumpToItem(CustomListView1.Size - 1)
    End If

If you do see the first messages then add a white panel above the layout and hide it after 100 milliseconds.
 
Upvote 0
Top