I am making a chat and I would like to load the customlistview that contains the conversation from the most recent to the oldest, loading from the bottom to the top, is it possible
thanks in advance
thanks in advance
clv.InsertAt(clv.size,pnl,clv.size)
clv.ScrollToItem(clv.Size-1)
' or
'clv.JumpToItem(clv.Size-1)
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage") 'Just a screen/form-filling CLV
Dim simulationText As String = $"
Me: Hello
You: What's up?
Me: Not much, and you?
You: Just passing time
Me: Let's paint the town
You: I've got the keys to the car. I'll be right there
"$
Dim exchange As List: exchange.Initialize
Dim v() As String = Regex.Split(CRLF, simulationText)
For Each s As String In v
If s.Trim.Length > 0 Then exchange.Add(s.trim)
Next
For Each s As String In exchange
addMessage(s)
Sleep(2000)
Next
End Sub
Private Sub addMessage(s As String)
Dim w() As String = Regex.Split("\: ", s)
Dim h As Float = 100 'compute the height of message instead (B4A StringUtils)
Dim pnl As B4XView = xui.CreatePanel("")
pnl.SetLayoutAnimated(0, 0, 0, Root.Width - 20, h)
Dim name As Label: name.Initialize("")
Dim namex As B4XView = name
namex.Text = w(0)
pnl.AddView(namex, 0, 0, pnl.Width, 20)
Dim message As Label: message.Initialize("")
Dim messagex As B4XView = message
If w(0) = "Me" Then
namex.SetTextAlignment("CENTER", "LEFT")
messagex.SetTextAlignment("CENTER", "LEFT")
namex.TextColor = xui.Color_Blue
messagex.TextColor = xui.Color_Blue
messagex.Text = " " & w(1)
Else
namex.SetTextAlignment("CENTER", "RIGHT")
messagex.SetTextAlignment("CENTER", "RIGHT")
namex.TextColor = xui.Color_Black
messagex.TextColor = xui.Color_Black
messagex.Text = w(1) & " "
End If
pnl.AddView(messagex, 0, namex.Height, pnl.Width, 30)
pnl.height = namex.Height + messagex.height
CustomListView1.InsertAt(0, pnl, s)
End Sub