As explained here: Get Key, not value, of the ListPreference selection - Possible? and many other places, it is quite easy to access ListPreferences labels from PreferenceActivity.
What I need to do is to read the label corresponding to the current selected from the main activity. But I can't find a way.
For example, in my main activity I have
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
I would like to use something like:
ListPreference listPreference = (ListPreference) settings.findPreference("list_of_countries");
And then handle it to get current value and label.
Update 01
I tried to handle another way to retrieve the summary (the name of a country in my example) value which I need to say the customer what he selected. I can't give him the code!
private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
String stringSummary = preference.getSummary().toString();
String stringKey = preference.getKey().toString();
if (stringKey.equals("list_of_countries")){
MyActivity.countryName = stringSummary;
}
Nothing to do... the OnPreferenceChangeListener is called.... BEFORE the preference change, i.e., when one item is clicked, so what I succeed to retrieve is just the past summary. I found no way.