Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView get scroll position?

Tags:

android

I'm using a MergeAdapter (from Mark Murphy's excellent series of projects). You use it with a ListView. I'm trying to rebuild the contents of the adapter on a refresh (instead of refreshing "in place" and calling notifyDataSetChange()).

I'd like to get the y-scroll value of the listview so I can reset to that after I rebuild my list. This doesn't seem to be possible?

Thanks

like image 716
user291701 Avatar asked Jun 02 '12 19:06

user291701


People also ask

How to get scroll position in ListView android?

Okay, I found a workaround, using the following code: View c = listview. getChildAt(0); int scrolly = -c.

How do I listen to scroll position in flutter?

I used NotificationListener that is a widget that listens for notifications bubbling up the tree. Then use ScrollEndNotification , which indicates that scrolling has stopped. For scroll position I used _scrollController that type is ScrollController .

How to save state of ListView in android?

Since the MainActivity goes to onPause() -> onStop() method when the user clicked a list item, I am saving the state of ListView inside onPause(). For get the return Parcelable value I use a global variable called state.


1 Answers

Implement OnScrollListener for your listview.

@Override
public void onScroll(AbsListView absListView, int firstVisible, int visibleCount, int totalCount) { 
//firstvisible is your first visible item in the list
}
like image 134
Tarun Avatar answered Oct 02 '22 13:10

Tarun