From 2ac93ae9194f84e18eafe07dc0304cfbb1297b00 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Fri, 28 Feb 2014 12:18:38 -0800 Subject: [PATCH] Don't smooth scroll if the adapter is null BUG: 13235508 Change-Id: I1ca8a5675aa07b9a987e47a6eacdc0a1e4adde74 --- core/java/android/widget/AbsListView.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java index ffd5c45fb5d0d..47d42dc287d0d 100644 --- a/core/java/android/widget/AbsListView.java +++ b/core/java/android/widget/AbsListView.java @@ -7160,8 +7160,14 @@ public abstract class AbsListView extends AdapterView implements Te return; } + if (mAdapter == null) { + // Can't scroll anywhere without an adapter. + return; + } + final int itemCount = getCount(); final int clampedPosition = MathUtils.constrain(targetPosition, 0, itemCount - 1); + final int clampedBoundPosition = MathUtils.constrain(boundPosition, 0, itemCount - 1); final int firstPosition = getFirstVisiblePosition(); final int lastPosition = firstPosition + getChildCount(); final int targetRow = getRowForPosition(clampedPosition); @@ -7180,8 +7186,8 @@ public abstract class AbsListView extends AdapterView implements Te } float endSubRow = targetRow; - if (boundPosition != INVALID_POSITION) { - final int boundRow = getRowForPosition(boundPosition); + if (clampedBoundPosition != INVALID_POSITION) { + final int boundRow = getRowForPosition(clampedBoundPosition); if (boundRow >= firstRow && boundRow < lastRow && boundRow != targetRow) { endSubRow = computeBoundSubRow(targetRow, boundRow); }