Skip to content

Commit 2dda21b

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Another stab at fixing issue #3149290 java.lang.RuntimeException:..." into gingerbread
2 parents 2bf89b2 + 7becaee commit 2dda21b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

core/java/android/widget/AbsListView.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff 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;

0 commit comments

Comments
 (0)