Skip to content

Instantly share code, notes, and snippets.

@Limuyang1013
Created January 4, 2016 08:36
Show Gist options
  • Save Limuyang1013/e93ccada6eac4c317666 to your computer and use it in GitHub Desktop.
Save Limuyang1013/e93ccada6eac4c317666 to your computer and use it in GitHub Desktop.
保存恢复ListView当前位置
private void saveCurrentPosition() {
if (mListView != null) {
int position = mListView.getFirstVisiblePosition();
View v = mListView.getChildAt(0);
int top = (v == null) ? 0 : v.getTop();
//保存position和top
}
}
private void restorePosition() {
if (mFolder != null && mListView != null) {
int position = 0;//取出保存的数据
int top = 0;//取出保存的数据
mListView.setSelectionFromTop(position, top);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment