Android Question custom listview scroll to end

Addo

Well-Known Member
Licensed User
Longtime User
i am using customlistview as chat view i am trying to scroll to the end of items but it doesnt go to the end

i do something like following each time i send text


B4X:
lstvv.AddTextItem("test text","Test")
lstvv.ScrollToItem(10000)

also i have noticed that whenever the keyboard showing i cannot see the top of the listview
 

Addo

Well-Known Member
Licensed User
Longtime User
this is how my ime looks like

B4X:
Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.LoadLayout("1")
   IME.Initialize("IME")
   IME.AddHeightChangedEvent
   IME_HeightChanged(100%y, 0)
   IME.AddHandleActionEvent(typingtxt)
 
   CallSub(Starter, "startconnectiontoserver")

End Sub


Sub IME_HeightChanged(NewHeight As Int, OldHeight As Int)
    Panel2.Top = NewHeight - Panel2.Height
    Panel1.Height = Panel2.Top - Panel1.Top
    lstvv.AsView.Height = Panel2.Top - lstvv.AsView.Top
End Sub


and this is the layout attached
 

Attachments

  • 1.bal
    4.6 KB · Views: 244
Upvote 0

Addo

Well-Known Member
Licensed User
Longtime User
just type and click send too many times like ordinary chat it will scroll but not to the last item , you will have to scroll to see the last inserted item
 

Attachments

  • test.zip
    4 KB · Views: 256
Upvote 0

Claudio Oliveira

Active Member
Licensed User
Longtime User
Hi @PassionDEV,

Once you defined Panel1.Height (which contains your CustomListView), all you have to do is
make sure your CustomListView isn't higher than Panel1.
So, change this line...
B4X:
lstvv.AsView.Height = Panel2.Top - lstvv.AsView.Top

To this line...
B4X:
lstvv.AsView.Height = Panel1.Height

... and you'll get what you want. ;)

I've tested your project here and it worked fine.

Regards
 
Upvote 0

Claudio Oliveira

Active Member
Licensed User
Longtime User
i did exactly this and still remains one item to scroll manually to it

Oh! Sorry!
I forgot another change I did. :D
In sendbtn_Click sub, I put a Sleep(0) to force any pending UI update to be processed before ScrollToItem call...

This is how sendbtn_Click sub code looks like.
B4X:
Sub sendbtn_Click
    lstvv.AddTextItem(typingtxt.Text,"Test")
    Sleep(0)
    lstvv.ScrollToItem(lstvv.Getsize - 1)
    typingtxt.Text = ""
    
End Sub

Regards
 
Upvote 0
Top