When a item of a ListFragment is clicked, its onClickListener gets evoked and the item opens. Now, when the back button is pressed the listfragment resumes but from starting element. How could the listfragment be resumed to the point where the item was clicked ? I think the answer is obvious but I want to be sure.
Asked
Active
Viewed 36 times
-2
-
possible duplicate of [Maintain/Save/Restore scroll position when returning to a ListView](http://stackoverflow.com/questions/3014089/maintain-save-restore-scroll-position-when-returning-to-a-listview) – 2Dee May 19 '15 at 08:27
1 Answers
1
Save the position (when changing Activity):
int index = listView.getFirstVisiblePosition();
View v = listView.getChildAt(0);
int position = (v == null) ? 0 : (v.getTop() - mList.getPaddingTop());
Restore the position (in onResume()):
listView.setSelectionFromTop(index, position);
-
1Instead of copying answers, please vote to close the question as duplicate, since you've already identified it as such... – 2Dee May 19 '15 at 08:27