Check if item is selectable before calling on click

This CL fixes a bug in ListView where it might call onClick on an
un-clickable if a new touch arrives before up timeout.

We could actually consider making child position non-changable
but that will change behavior. This seems safer approach.

Bug: 27198796
Change-Id: I7b15d04efa19d1d760a294bd027f3da3aaa3a445
This commit is contained in:
Yigit Boyar
2016-03-01 16:09:58 -08:00
parent ccb7f018e6
commit 418d0cf5c9

View File

@@ -3078,7 +3078,8 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
final int motionPosition = mClickMotionPosition;
if (adapter != null && mItemCount > 0 &&
motionPosition != INVALID_POSITION &&
motionPosition < adapter.getCount() && sameWindow()) {
motionPosition < adapter.getCount() && sameWindow() &&
adapter.isEnabled(motionPosition)) {
final View view = getChildAt(motionPosition - mFirstPosition);
// If there is no view, something bad happened (the view scrolled off the
// screen, etc.) and we should cancel the click