From e28c03b620c3252b1c24fc326a3a9b4af93ce722 Mon Sep 17 00:00:00 2001 From: Phil Weaver Date: Mon, 24 Apr 2017 13:23:10 -0700 Subject: [PATCH] Use newest scrap view in ListView When a ListView's contents change, it first measures, using a view at position 0. It then scraps that view, and then scraps all of its other views. Two scrap views thus exist for position 0. Since we were retrieving the oldest scrap view, we would toggle between two different views at position 0. This toggling confuses accessibility. This change takes the newest view from the scap heap, so the view that was recycled last (which is the one shown on the screen) is re-used for the screen. The view used for measuring sticks around and is available for measure again. Bug: 33788047 Test: I verified that the switch state is announced correctly for the cases found in the bug. Change-Id: I936e5ad09c3594e33e80dc39236025bf8bc877b8 --- core/java/android/widget/AbsListView.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java index 1c87726b3ca9e..5476ab216f2f5 100644 --- a/core/java/android/widget/AbsListView.java +++ b/core/java/android/widget/AbsListView.java @@ -7088,7 +7088,8 @@ public abstract class AbsListView extends AdapterView implements Te final int size = scrapViews.size(); if (size > 0) { // See if we still have a view for this position or ID. - for (int i = 0; i < size; i++) { + // Traverse backwards to find the most recently used scrap view + for (int i = size - 1; i >= 0; i--) { final View view = scrapViews.get(i); final AbsListView.LayoutParams params = (AbsListView.LayoutParams) view.getLayoutParams();