From 91c8613679959a5fde4f72fe6dd80023d9a1a9e7 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Fri, 26 Mar 2010 17:29:45 -0700 Subject: [PATCH] Don't assume there's a selected position in touch mode. Bug #2520743 Bad GridView, bad! Change-Id: Ideed32dc70a69c85df5afbf949e78b481e147b7f --- core/java/android/widget/GridView.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/java/android/widget/GridView.java b/core/java/android/widget/GridView.java index be633be65084c..d8679802a42d4 100644 --- a/core/java/android/widget/GridView.java +++ b/core/java/android/widget/GridView.java @@ -1128,11 +1128,13 @@ public class GridView extends AbsListView { default: if (childCount == 0) { if (!mStackFromBottom) { - setSelectedPositionInt(0); + setSelectedPositionInt(mAdapter == null || isInTouchMode() ? + INVALID_POSITION : 0); sel = fillFromTop(childrenTop); } else { final int last = mItemCount - 1; - setSelectedPositionInt(last); + setSelectedPositionInt(mAdapter == null || isInTouchMode() ? + INVALID_POSITION : last); sel = fillFromBottom(last, childrenBottom); } } else {