Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

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?

like image 611
Ollie C Avatar asked Feb 21 '11 23:02

Ollie C


1 Answers

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);
like image 54
Manfred Moser Avatar answered Sep 21 '22 14:09

Manfred Moser