My ListView (StickyListHeadersListView) does not save the exact scroll position. I referenced this:
Maintain/Save/Restore scroll position when returning to a ListView
When a user taps on an item in the list, I use SharedPreferences to save the "index" and "top" before the app transitions to an activity. When I press back on the activity to go back to the fragment with the ListView, the list goes to the top of the first visible list item from when it left, but not the exact position (i.e. if the first visible item is cut off halfway, it should be cut off halfway when returning to the fragment).
In other words, the offset is not saving. Like I said, it can save the first visible position, but the exact scroll is not being saved.
mAdapter = new PeopleAdapter(getActivity(), null);
mList = (StickyListHeadersListView) rootView.findViewById(R.id.stickyList);
mList.setAdapter(mAdapter);
mList.setAreHeadersSticky(true);
mList.setDividerHeight(0);
mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor cursor = mAdapter.getCursor();
if (cursor != null && cursor.moveToPosition(position)) {
MainActivity.setIndex(mList.getFirstVisiblePosition());
View v = mList.getListChildAt(0);
int top = (v == null) ? 0 : (v.getTop() - mList.getPaddingTop());
MainActivity.setTop(top);
Intent intent = new Intent(getActivity(), ContactDetailActivity.class);
startActivity(intent);
}
});
After the cursor is done loading, I'm calling
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
android.util.Log.i(TAG, "Cursor loaded. (" + data.getCount() + " rows)");
mList.setSelectionFromTop(MainActivity.getIndex(), MainActivity.getTop());
mAdapter.changeCursor(data);
mAdapter.notifyDataSetChanged();
}