How to scroll ListView to the bottom?

Sver picture Sver · Sep 25, 2013 · Viewed 35.1k times · Source

I though this would be a simple task, but apparently there is no way to scroll listview to the bottom. All solutions that I found are using variations of setSelection(lastItem) method which only sets selection to last item, but does not scrolls to the bottom of it.

In my case I have a empty listview (with a long empty view header set) and I want to scroll to bottom of it.

So, is there a way to do it?

Edit:

So for those who are interested the working solution is:

getListView().setSelectionFromTop(0, -mHeader.getHeight());

and

getListView().scrollTo(mOffset)

This also works, with right offset (calculated based on current scroll position), but might give you some unexpected results.

Answer

Rana Ranvijay Singh picture Rana Ranvijay Singh · May 3, 2014

If you want the list view to be scrolled always at the bottom even when you are updating the list view dynamically then you can add these attributes in list view itself.

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