To set the summary of a ListPreference
to the value selected in a dialog you could use this code:
package yourpackage;
import android.content.Context;
import android.util.AttributeSet;
public class ListPreference extends android.preference.ListPreference {
public ListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
if (positiveResult) setSummary(getEntry());
}
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
super.onSetInitialValue(restoreValue, defaultValue);
setSummary(getEntry());
}
}
and reference the yourpackage.ListPreference
object in your preferences.xml
remembering to specify there your android:defaultValue
as this triggers the call to onSetInitialValue()
.
If you want you can then modify the text before calling setSummary()
to whatever suits your application.