The problem itself is not difficult, but because the requirements in the project are too complex, the result is that the problem becomes less easily realized. On the Internet a search, the results are as follows:
I don't know who's copy who? Anyway introduced by the so-called three methods, the first is not able to run, very obvious bug, the 23rd method is the entry-level knowledge, these big Brother blogging themselves do not first run a bit?
Alas, do not spit groove, talk about my solution:
Perform the following actions where you want to record the scroll position:
int scrollPos = refreshListView.getFirstVisiblePosition(); View v1 = refreshListView.getChildAt(0); intnull0 : v1.getTop();
The Getfirstvisibleposition method is used to record the index of the currently first visible item.
int scrolltop = (V1 = = null)? 0:v1.gettop (); The offset that is used to record the current first visible item.
Attention
In your project, you may need to View v1 = refreshListView.getChildAt(0); add a non-null judgment to determine if the data set that is appropriate to the ListView is empty.
Perform the following actions where you need to restore the scroll position:
.setSelectionFromTop(scrollPos, scrollTop);
Some people may choose to record the current position of the first visible item, and then use the SetSelection method to recover the location, so it is not impossible, but not accurate enough, because in many cases the top item in our ListView is not necessarily just shown, May show half of the hidden half. So personally think the method described above is more appropriate.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. If there is a wrong place, I would appreciate it if I could criticize it.
Android Development record ListView scroll position