开发者

How to retain Android ListView scroll position when returning to an activity? [duplicate]

开发者 https://www.devze.com 2023-02-12 05:33 出处:网络
This question already has answers here: Closed 10 years ago. 开发者_JAVA百科 Possible Duplicate: Maintain/Save/Restore scroll position when returning to a ListView
This question already has answers here: Closed 10 years ago. 开发者_JAVA百科

Possible Duplicate:

Maintain/Save/Restore scroll position when returning to a ListView

The user views a listview of items, they move to an activity that shows detail for one item, and then hit Back and return to the list activity but I want the list to reflect its prior scroll position.

Should I store the scroll position as a member variable on the activity in onPause or is there a better way?


Save the position in an instance variable on onPause and in onResume check if there is position value and move to it.

e.g. using

private int currentPostion;

and then in onResume do..

getListView().setSelection(currentPosition);
0

精彩评论

暂无评论...
验证码 换一张
取 消