@@ -39,6 +39,7 @@ public class ListPreference extends DialogPreference {
3939 private CharSequence [] mEntries ;
4040 private CharSequence [] mEntryValues ;
4141 private String mValue ;
42+ private String mSummary ;
4243 private int mClickedDialogEntryIndex ;
4344
4445 public ListPreference (Context context , AttributeSet attrs ) {
@@ -49,8 +50,16 @@ public ListPreference(Context context, AttributeSet attrs) {
4950 mEntries = a .getTextArray (com .android .internal .R .styleable .ListPreference_entries );
5051 mEntryValues = a .getTextArray (com .android .internal .R .styleable .ListPreference_entryValues );
5152 a .recycle ();
53+
54+ /* Retrieve the Preference summary attribute since it's private
55+ * in the Preference class.
56+ */
57+ a = context .obtainStyledAttributes (attrs ,
58+ com .android .internal .R .styleable .Preference , 0 , 0 );
59+ mSummary = a .getString (com .android .internal .R .styleable .Preference_summary );
60+ a .recycle ();
5261 }
53-
62+
5463 public ListPreference (Context context ) {
5564 this (context , null );
5665 }
@@ -126,6 +135,43 @@ public void setValue(String value) {
126135 persistString (value );
127136 }
128137
138+ /**
139+ * Returns the summary of this ListPreference. If the summary
140+ * has a {@linkplain java.lang.String#format String formatting}
141+ * marker in it (i.e. "%s" or "%1$s"), then the current entry
142+ * value will be substituted in its place.
143+ *
144+ * @return the summary with appropriate string substitution
145+ */
146+ @ Override
147+ public CharSequence getSummary () {
148+ final CharSequence entry = getEntry ();
149+ if (mSummary == null || entry == null ) {
150+ return super .getSummary ();
151+ } else {
152+ return String .format (mSummary , entry );
153+ }
154+ }
155+
156+ /**
157+ * Sets the summary for this Preference with a CharSequence.
158+ * If the summary has a
159+ * {@linkplain java.lang.String#format String formatting}
160+ * marker in it (i.e. "%s" or "%1$s"), then the current entry
161+ * value will be substituted in its place when it's retrieved.
162+ *
163+ * @param summary The summary for the preference.
164+ */
165+ @ Override
166+ public void setSummary (CharSequence summary ) {
167+ super .setSummary (summary );
168+ if (summary == null && mSummary != null ) {
169+ mSummary = null ;
170+ } else if (summary != null && !summary .equals (mSummary )) {
171+ mSummary = summary .toString ();
172+ }
173+ }
174+
129175 /**
130176 * Sets the value to the given index from the entry values.
131177 *
0 commit comments