代码片段,双击复制
backgroundList.setOnScrollListener(scrollListener);
|
代码片段,双击复制
private OnScrollListener scrollListener = new OnScrollListener() {
@Override
public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3) {
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
scrollPos = myList.getFirstVisiblePosition();
}
if (arrayList != null ) {
View v=myList .getChildAt( 0 );
scrollTop=(v== null )? 0 :v.getTop();
}
}
};
|
调用setAdapter之后恢复位置:
代码片段,双击复制
myList .setSelectionFromTop(scrollPos, scrollTop);
|
参考:http://stackoverflow.com/questions/3014089/scroll-to-a-position-in-a-listview