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

Commit 2d43d283 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Handle the case of Preference lists that have header views inserted at the top.

Without this change, wrong Preference is returned when you select one.
Subtract the number of headers from the index before querying the adapter.
Needed for:
Bug: 5203189

Change-Id: Iba7277789ebbd7e3e9954931b1ea06c7e34f3c15
parent 2452ad30
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.Window;
import android.widget.AbsListView;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ListAdapter;
@@ -190,6 +191,10 @@ public final class PreferenceScreen extends PreferenceGroup implements AdapterVi
    }

    public void onItemClick(AdapterView parent, View view, int position, long id) {
        // If the list has headers, subtract them from the index.
        if (parent instanceof ListView) {
            position -= ((ListView) parent).getHeaderViewsCount();
        }
        Object item = getRootAdapter().getItem(position);
        if (!(item instanceof Preference)) return;