Skip to content

Commit 966222e

Browse files
Amith YamasaniAndroid (Google) Code Review
authored andcommitted
Merge "Handle the case of Preference lists that have header views inserted at the top."
2 parents 1e70aa9 + 2d43d28 commit 966222e

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)