Recording the scroll position of ListView in android Development
This problem is not difficult, but it is not so easy to implement because the project requirements are too complicated. Search on the Internet and the results are as follows:
I don't know. who is the cZ operator? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> vcHkgd2hvo7 + 3tNX9venJ3LXEy/keys + keys/Cw + a1xLLZ1/keys" brush: java; ">int scrollPos = refreshListView.getFirstVisiblePosition(); View v1 = refreshListView.getChildAt(0); int scrollTop = (v1 == null) ? 0 : v1.getTop();
The getFirstVisiblePosition method is used to record the index of the first visible item.
Int scrollTop = (v1 = null )? 0: v1.getTop (); used to record the offset of the first visible item.
Note:
In your project, you may needView v1 = refreshListView.getChildAt(0);
Add a non-empty judgment to determine whether the dataset adapted to ListView is empty.
To restore the scroll position, perform the following operations:
refreshListView .setSelectionFromTop(scrollPos, scrollTop);
Some may choose to record the current position of the first visible item, and then use the setSelection method to restore the position. This is not impossible, but not accurate enough, in many cases, the top items in the ListView are not necessarily just displayed, but may be half hidden. Therefore, I personally think the method described above is more appropriate.