-2

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.

  • 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 Answers1

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);


Source: https://stackoverflow.com/a/3035521/3621175

Community
  • 1
  • 1
PatrickMA
  • 857
  • 7
  • 23