Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scroll ListView to the bottom?

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.

like image 221
Sver Avatar asked Sep 25 '13 05:09

Sver


People also ask

How do you scroll a list in flutter?

All you have to do is set Global Keys for your widgets and call Scrollable. ensureVisible on the key of your widget you want to scroll to. For this to work your ListView should be a finite List of objects. If you are using ListView.


2 Answers

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"
like image 70
Rana Ranvijay Singh Avatar answered Sep 27 '22 22:09

Rana Ranvijay Singh


use the following

    lv.setSelection(adapter.getCount() - 1);
like image 22
WISHY Avatar answered Sep 27 '22 20:09

WISHY