Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2d60f950 authored by Gary Mai's avatar Gary Mai Committed by android-build-merger
Browse files

Cherry pick IndexListAdapter fix into i-dev

am: 85a683d0

Change-Id: I588f244761c785f36431456e6d9f5e6e96414f7b
parents efc0d329 85a683d0
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -173,7 +173,7 @@ public abstract class IndexerListAdapter extends PinnedHeaderListAdapter impleme
            if (section == -1) {
                listView.setHeaderInvisible(index, false);
            } else {
                View topChild = listView.getChildAt(listPosition);
                View topChild = getViewAtVisiblePosition(listView, listPosition);
                if (topChild != null) {
                    // Match the pinned header's height to the height of the list item.
                    mHeader.setMinimumHeight(topChild.getMeasuredHeight());
@@ -194,6 +194,26 @@ public abstract class IndexerListAdapter extends PinnedHeaderListAdapter impleme
        }
    }

    /**
     * Returns the view used for the specified list position assuming it is visible or null if
     * it isn't.
     *
     * <p>This makes some assumptions about the implementation of ListView (child views are the
     * item views and are ordered in the same way as the adapter items they are displaying)
     * but they are probably safe given that the API is stable.</p>
     */
    private View getViewAtVisiblePosition(ListView list, int position) {
        final int firstVisiblePosition = list.getFirstVisiblePosition();
        final int childCount = list.getChildCount();
        final int index = position - firstVisiblePosition;
        if (index >= 0 && index < childCount) {
            // Position is on-screen, use existing view.
            return list.getChildAt(index);
        } else {
            return null;
        }
    }

    /**
     * Computes the item's placement within its section and populates the {@code placement}
     * object accordingly.  Please note that the returned object is volatile and should be