One option would be you save the index and the position of the first item on the list before going to the layout details, this is if you are not finishing the item screen. The reason you are losing position is because in onResume
from the items screen, be checking the list again (check this). See then how it would be:
int index = listview.getFirstVisiblePosition();
View v = listview.getChildAt(0);
int itemTop = (v == null) ? 0 : (v.getTop() - listview.getPaddingTop());
To restore, you can use the method setSelectionFromTop
in his onResume()
:
listview.setSelectionFromTop(index, itemTop);
Behold that answer in the Soen.
Another option would be to save the state using Parcelable
. Exploring the life cycle of Activity, you use the onPause
so that the moment you exit the activity, save the state using onSaveInstanceState
list by list. See an example:
Parcelable state;
@Override
public void onPause() {
state = listview.onSaveInstanceState();
super.onPause();
}
To restore, check first if there is a saved state, an example, if a value has been assigned to a variable state
. Soon after, use the method onRestoreInstanceState
passing as parameter the state. See:
if(state != null) {
listview.onRestoreInstanceState(state);
}
Welcome! Please suggest that take a tour of the site and see How to create a Minimum, Complete and Verifiable Example! So make it easier for the community to help you!
– Thiago Luiz Domacoski
You kill the Activity that’s on the list?
– Thiago Luiz Domacoski