Skip to content

Commit 2d43d28

Browse files
author
Amith Yamasani
committed
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
1 parent 2452ad3 commit 2d43d28

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

core/java/android/preference/PreferenceScreen.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import android.util.AttributeSet;
2727
import android.view.View;
2828
import android.view.Window;
29+
import android.widget.AbsListView;
2930
import android.widget.Adapter;
3031
import android.widget.AdapterView;
3132
import android.widget.ListAdapter;
@@ -190,9 +191,13 @@ public Dialog getDialog() {
190191
}
191192

192193
public void onItemClick(AdapterView parent, View view, int position, long id) {
194+
// If the list has headers, subtract them from the index.
195+
if (parent instanceof ListView) {
196+
position -= ((ListView) parent).getHeaderViewsCount();
197+
}
193198
Object item = getRootAdapter().getItem(position);
194199
if (!(item instanceof Preference)) return;
195-
200+
196201
final Preference preference = (Preference) item;
197202
preference.performClick(this);
198203
}

0 commit comments

Comments
 (0)