File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -974,8 +974,16 @@ public Parcelable onSaveInstanceState() {
974974 ss .position = getSelectedItemPosition ();
975975 ss .firstId = INVALID_POSITION ;
976976 } else {
977- if (haveChildren ) {
978- // Remember the position of the first child
977+ if (haveChildren && mFirstPosition > 0 ) {
978+ // Remember the position of the first child.
979+ // We only do this if we are not currently at the top of
980+ // the list, for two reasons:
981+ // (1) The list may be in the process of becoming empty, in
982+ // which case mItemCount may not be 0, but if we try to
983+ // ask for any information about position 0 we will crash.
984+ // (2) Being "at the top" seems like a special case, anyway,
985+ // and the user wouldn't expect to end up somewhere else when
986+ // they revisit the list even if its content has changed.
979987 View v = getChildAt (0 );
980988 ss .viewTop = v .getTop ();
981989 int firstPos = mFirstPosition ;
You can’t perform that action at this time.
0 commit comments