Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scroll to the bottom of ListView programmatically?

After calling notifydatasetchanged(); I want to scroll to the bottom of list so that user see the last record in the Listview.

(I am writing Chat module so for that purpose I need latest record at the bottom of list to be visible)

Can any one guide me how to achieve this?

like image 229
UMAR-MOBITSOLUTIONS Avatar asked Mar 29 '10 09:03

UMAR-MOBITSOLUTIONS


People also ask

How do I scroll to end of ListView in flutter?

position. maxScrollExtent; This simply means we are asking for the last position in the ListView via ScrollController. And then, we asked the ScrollController to move the position we got above using the jumpTo function.

Does ListView have scroll?

A ListView in Android is a scrollable list used to display items.


1 Answers

I know that this has been answered and you took the answer and it was more than a year ago. But a better way to do this is Transcript Mode. For a demo, see the Android API Demo under Views > Lists > Transcript.

You would set the following on your list view in the XML.

android:stackFromBottom="true" android:transcriptMode="alwaysScroll" 

It will always work whenever you call notifyDataSetChanged(). You can set android:transcriptMode to normal instead if you want an even better result for chat applications: it will scroll to the bottom only if the last item was already in view. That way your users can view the previous chat without interruption when other users chat.

  • transcript mode
  • stack from bottom
like image 73
Ribose Avatar answered Sep 25 '22 17:09

Ribose