Add support for saving and using the Preference's key value
- make public and hide the PreferenceGroupAdapter class - add setActivated(int position) to be able to set the activated item - udpate getView(int position, View convertView, ViewGroup parent) to set/unset the activated item Change-Id: I8a653ad6541bb6b7a043ba7c3d95e5ecad924a0d
This commit is contained in:
@@ -45,8 +45,11 @@ import android.widget.ListView;
|
|||||||
* adapter, use {@link PreferenceCategoryAdapter} instead.
|
* adapter, use {@link PreferenceCategoryAdapter} instead.
|
||||||
*
|
*
|
||||||
* @see PreferenceCategoryAdapter
|
* @see PreferenceCategoryAdapter
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
*/
|
*/
|
||||||
class PreferenceGroupAdapter extends BaseAdapter implements OnPreferenceChangeInternalListener {
|
public class PreferenceGroupAdapter extends BaseAdapter
|
||||||
|
implements OnPreferenceChangeInternalListener {
|
||||||
|
|
||||||
private static final String TAG = "PreferenceGroupAdapter";
|
private static final String TAG = "PreferenceGroupAdapter";
|
||||||
|
|
||||||
@@ -88,6 +91,8 @@ class PreferenceGroupAdapter extends BaseAdapter implements OnPreferenceChangeIn
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private int mActivatedPosition = -1;
|
||||||
|
|
||||||
private static class PreferenceLayout implements Comparable<PreferenceLayout> {
|
private static class PreferenceLayout implements Comparable<PreferenceLayout> {
|
||||||
private int resId;
|
private int resId;
|
||||||
private int widgetResId;
|
private int widgetResId;
|
||||||
@@ -207,6 +212,10 @@ class PreferenceGroupAdapter extends BaseAdapter implements OnPreferenceChangeIn
|
|||||||
return this.getItem(position).getId();
|
return this.getItem(position).getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setActivated(int position) {
|
||||||
|
mActivatedPosition = position;
|
||||||
|
}
|
||||||
|
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
final Preference preference = this.getItem(position);
|
final Preference preference = this.getItem(position);
|
||||||
// Build a PreferenceLayout to compare with known ones that are cacheable.
|
// Build a PreferenceLayout to compare with known ones that are cacheable.
|
||||||
@@ -217,8 +226,9 @@ class PreferenceGroupAdapter extends BaseAdapter implements OnPreferenceChangeIn
|
|||||||
if (Collections.binarySearch(mPreferenceLayouts, mTempPreferenceLayout) < 0) {
|
if (Collections.binarySearch(mPreferenceLayouts, mTempPreferenceLayout) < 0) {
|
||||||
convertView = null;
|
convertView = null;
|
||||||
}
|
}
|
||||||
|
View result = preference.getView(convertView, parent);
|
||||||
return preference.getView(convertView, parent);
|
result.setActivated(position == mActivatedPosition);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -23,7 +23,8 @@
|
|||||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:paddingStart="@dimen/preference_item_padding_side"
|
android:paddingStart="@dimen/preference_item_padding_side"
|
||||||
android:paddingEnd="?android:attr/scrollbarSize">
|
android:paddingEnd="?android:attr/scrollbarSize"
|
||||||
|
android:background="?android:attr/activatedBackgroundIndicator">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
Reference in New Issue
Block a user