ListView.getScrollY() returns 0 because you are not scrolling the ListView itself, but the View inside it. Calling "getScrollY ()" on any of the "View" you scroll through returns the actual values (only to some extent, since they are being processed).
To maintain your position, try the following:
@Override protected void onSaveInstanceState (Bundle outState) { super.onSaveInstanceState(outState); int scrollPos = mListView.getSelectedItemPosition(); outState.putInt("MyPosition", scrollPos); } @Override public void onRestoreInstanceState(Bundle inState) { super.onRestoreInstanceState(inState); int scrollPos = inState.getInt("MyPosition"); mListView.setSelection(scrollPos); }
Good luck
source share