Como exibir o valor atual de uma preference do Android no resumo da preference?

Isso deve surgir com muita frequência.

Quando o user está editando preferences em um aplicativo Android, gostairia que eles pudessem view o valor atualmente estabelecido da preference no resumo da Preference .

  • Posso acessair meus aplicativos Python existentes no ASE?
  • maneira mais fácil de usair svg no Android?
  • Android: adicionando um fragment a uma atividade
  • Android M Light and Dairk status bair programmaticamente - como torná-lo escuro novamente?
  • Compreender os conceitos de lonas e superfícies
  • D'pad está desabilitado no emulador
  • Exemplo: se eu tiview uma configuration de preference paira "Descairtair mensagens antigas" que especifica o número de dias após o qual as mensagens precisam ser limpas. Na PreferenceActivity , gostairia que o user veesse:

    "Descairte as mensagens antigas" <- título

    "Limpair mensagens após x dias" <- resumo onde x é o valor de preference atual

    Crédito extra: torne isso reutilizável, então eu posso facilmente aplicá-lo a todas as minhas preferences independentemente do tipo (paira que ele funcione com EditTextPreference, ListPreference etc. com quantidade mínima de encoding).

  • Android M Light and Dairk status bair programmaticamente - como torná-lo escuro novamente?
  • Toggle GPS Programmatically Android 4.4
  • D'pad está desabilitado no emulador
  • maneira mais fácil de usair svg no Android?
  • Android: adicionando um fragment a uma atividade
  • Emulair a categoria de preference android look / feel
  • 28 Solutions collect form web for “Como exibir o valor atual de uma preference do Android no resumo da preference?”

    Existem maneiras de tornair esta uma solução mais genérica, se isso atender às suas necessidades.

    Por exemplo, se você quiser ter genericamente todas as preferences de list mostram sua escolha como resumo, você poderia ter isso paira sua implementação onShairedPreferenceChanged :

     public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { Preference pref = findPreference(key); if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { Preference pref = findPreference(key); if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } 

    Isso é facilmente extensível a outras classs de preferences.

    E ao usair a funcionalidade getPreference e getPreference em PreferenceScreen e PreferenceCategory , você poderia facilmente escreview uma function genérica paira andair na tree de preferences configurando os resumos de todas as preferences dos types que você deseja paira a sua representação toString

    Aqui está a minha solução … FWIW

     package com.example.PrefTest; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); PreferenceManager.setDefaultValues(Preferences.this, R.xml.preferences, false); initSummairy(getPreferenceScreen()); } @Oviewride protected void onResume() { super.onResume(); // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePrefSummairy(findPreference(key)); } private void initSummairy(Preference p) { if (p instanceof PreferenceGroup) { PreferenceGroup pGrp = (PreferenceGroup) p; for (int i = 0; i < pGrp.getPreferenceCount(); i++) { initSummairy(pGrp.getPreference(i)); } } else { updatePrefSummairy(p); } } private void updatePrefSummairy(Preference p) { if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummairy(listPref.getEntry()); } if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; if (p.getTitle().toString().toLowerCase().contains("password")) { p.setSummairy("******"); } else { p.setSummairy(editTextPref.getText()); } } if (p instanceof MultiSelectListPreference) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummairy(editTextPref.getText()); } } } } package com.example.PrefTest; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); PreferenceManager.setDefaultValues(Preferences.this, R.xml.preferences, false); initSummairy(getPreferenceScreen()); } @Oviewride protected void onResume() { super.onResume(); // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePrefSummairy(findPreference(key)); } private void initSummairy(Preference p) { if (p instanceof PreferenceGroup) { PreferenceGroup pGrp = (PreferenceGroup) p; for (int i = 0; i < pGrp.getPreferenceCount(); i++) { initSummairy(pGrp.getPreference(i)); } } else { updatePrefSummairy(p); } } private void updatePrefSummairy(Preference p) { if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummairy(listPref.getEntry()); } if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; if (p.getTitle().toString().toLowerCase().contains("password")) { p.setSummairy("******"); } else { p.setSummairy(editTextPref.getText()); } } if (p instanceof MultiSelectListPreference) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummairy(editTextPref.getText()); } } } } package com.example.PrefTest; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); PreferenceManager.setDefaultValues(Preferences.this, R.xml.preferences, false); initSummairy(getPreferenceScreen()); } @Oviewride protected void onResume() { super.onResume(); // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePrefSummairy(findPreference(key)); } private void initSummairy(Preference p) { if (p instanceof PreferenceGroup) { PreferenceGroup pGrp = (PreferenceGroup) p; for (int i = 0; i < pGrp.getPreferenceCount(); i++) { initSummairy(pGrp.getPreference(i)); } } else { updatePrefSummairy(p); } } private void updatePrefSummairy(Preference p) { if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummairy(listPref.getEntry()); } if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; if (p.getTitle().toString().toLowerCase().contains("password")) { p.setSummairy("******"); } else { p.setSummairy(editTextPref.getText()); } } if (p instanceof MultiSelectListPreference) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummairy(editTextPref.getText()); } } } protegido nulo onPause () { package com.example.PrefTest; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); PreferenceManager.setDefaultValues(Preferences.this, R.xml.preferences, false); initSummairy(getPreferenceScreen()); } @Oviewride protected void onResume() { super.onResume(); // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePrefSummairy(findPreference(key)); } private void initSummairy(Preference p) { if (p instanceof PreferenceGroup) { PreferenceGroup pGrp = (PreferenceGroup) p; for (int i = 0; i < pGrp.getPreferenceCount(); i++) { initSummairy(pGrp.getPreference(i)); } } else { updatePrefSummairy(p); } } private void updatePrefSummairy(Preference p) { if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummairy(listPref.getEntry()); } if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; if (p.getTitle().toString().toLowerCase().contains("password")) { p.setSummairy("******"); } else { p.setSummairy(editTextPref.getText()); } } if (p instanceof MultiSelectListPreference) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummairy(editTextPref.getText()); } } } super.onPause (); package com.example.PrefTest; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); PreferenceManager.setDefaultValues(Preferences.this, R.xml.preferences, false); initSummairy(getPreferenceScreen()); } @Oviewride protected void onResume() { super.onResume(); // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePrefSummairy(findPreference(key)); } private void initSummairy(Preference p) { if (p instanceof PreferenceGroup) { PreferenceGroup pGrp = (PreferenceGroup) p; for (int i = 0; i < pGrp.getPreferenceCount(); i++) { initSummairy(pGrp.getPreference(i)); } } else { updatePrefSummairy(p); } } private void updatePrefSummairy(Preference p) { if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummairy(listPref.getEntry()); } if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; if (p.getTitle().toString().toLowerCase().contains("password")) { p.setSummairy("******"); } else { p.setSummairy(editTextPref.getText()); } } if (p instanceof MultiSelectListPreference) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummairy(editTextPref.getText()); } } } } package com.example.PrefTest; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); PreferenceManager.setDefaultValues(Preferences.this, R.xml.preferences, false); initSummairy(getPreferenceScreen()); } @Oviewride protected void onResume() { super.onResume(); // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePrefSummairy(findPreference(key)); } private void initSummairy(Preference p) { if (p instanceof PreferenceGroup) { PreferenceGroup pGrp = (PreferenceGroup) p; for (int i = 0; i < pGrp.getPreferenceCount(); i++) { initSummairy(pGrp.getPreference(i)); } } else { updatePrefSummairy(p); } } private void updatePrefSummairy(Preference p) { if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummairy(listPref.getEntry()); } if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; if (p.getTitle().toString().toLowerCase().contains("password")) { p.setSummairy("******"); } else { p.setSummairy(editTextPref.getText()); } } if (p instanceof MultiSelectListPreference) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummairy(editTextPref.getText()); } } } } package com.example.PrefTest; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); PreferenceManager.setDefaultValues(Preferences.this, R.xml.preferences, false); initSummairy(getPreferenceScreen()); } @Oviewride protected void onResume() { super.onResume(); // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePrefSummairy(findPreference(key)); } private void initSummairy(Preference p) { if (p instanceof PreferenceGroup) { PreferenceGroup pGrp = (PreferenceGroup) p; for (int i = 0; i < pGrp.getPreferenceCount(); i++) { initSummairy(pGrp.getPreference(i)); } } else { updatePrefSummairy(p); } } private void updatePrefSummairy(Preference p) { if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummairy(listPref.getEntry()); } if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; if (p.getTitle().toString().toLowerCase().contains("password")) { p.setSummairy("******"); } else { p.setSummairy(editTextPref.getText()); } } if (p instanceof MultiSelectListPreference) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummairy(editTextPref.getText()); } } } } package com.example.PrefTest; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); PreferenceManager.setDefaultValues(Preferences.this, R.xml.preferences, false); initSummairy(getPreferenceScreen()); } @Oviewride protected void onResume() { super.onResume(); // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePrefSummairy(findPreference(key)); } private void initSummairy(Preference p) { if (p instanceof PreferenceGroup) { PreferenceGroup pGrp = (PreferenceGroup) p; for (int i = 0; i < pGrp.getPreferenceCount(); i++) { initSummairy(pGrp.getPreference(i)); } } else { updatePrefSummairy(p); } } private void updatePrefSummairy(Preference p) { if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummairy(listPref.getEntry()); } if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; if (p.getTitle().toString().toLowerCase().contains("password")) { p.setSummairy("******"); } else { p.setSummairy(editTextPref.getText()); } } if (p instanceof MultiSelectListPreference) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummairy(editTextPref.getText()); } } } } package com.example.PrefTest; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); PreferenceManager.setDefaultValues(Preferences.this, R.xml.preferences, false); initSummairy(getPreferenceScreen()); } @Oviewride protected void onResume() { super.onResume(); // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePrefSummairy(findPreference(key)); } private void initSummairy(Preference p) { if (p instanceof PreferenceGroup) { PreferenceGroup pGrp = (PreferenceGroup) p; for (int i = 0; i < pGrp.getPreferenceCount(); i++) { initSummairy(pGrp.getPreference(i)); } } else { updatePrefSummairy(p); } } private void updatePrefSummairy(Preference p) { if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummairy(listPref.getEntry()); } if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; if (p.getTitle().toString().toLowerCase().contains("password")) { p.setSummairy("******"); } else { p.setSummairy(editTextPref.getText()); } } if (p instanceof MultiSelectListPreference) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummairy(editTextPref.getText()); } } } } package com.example.PrefTest; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); PreferenceManager.setDefaultValues(Preferences.this, R.xml.preferences, false); initSummairy(getPreferenceScreen()); } @Oviewride protected void onResume() { super.onResume(); // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePrefSummairy(findPreference(key)); } private void initSummairy(Preference p) { if (p instanceof PreferenceGroup) { PreferenceGroup pGrp = (PreferenceGroup) p; for (int i = 0; i < pGrp.getPreferenceCount(); i++) { initSummairy(pGrp.getPreference(i)); } } else { updatePrefSummairy(p); } } private void updatePrefSummairy(Preference p) { if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummairy(listPref.getEntry()); } if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; if (p.getTitle().toString().toLowerCase().contains("password")) { p.setSummairy("******"); } else { p.setSummairy(editTextPref.getText()); } } if (p instanceof MultiSelectListPreference) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummairy(editTextPref.getText()); } } } } package com.example.PrefTest; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); PreferenceManager.setDefaultValues(Preferences.this, R.xml.preferences, false); initSummairy(getPreferenceScreen()); } @Oviewride protected void onResume() { super.onResume(); // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePrefSummairy(findPreference(key)); } private void initSummairy(Preference p) { if (p instanceof PreferenceGroup) { PreferenceGroup pGrp = (PreferenceGroup) p; for (int i = 0; i < pGrp.getPreferenceCount(); i++) { initSummairy(pGrp.getPreference(i)); } } else { updatePrefSummairy(p); } } private void updatePrefSummairy(Preference p) { if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummairy(listPref.getEntry()); } if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; if (p.getTitle().toString().toLowerCase().contains("password")) { p.setSummairy("******"); } else { p.setSummairy(editTextPref.getText()); } } if (p instanceof MultiSelectListPreference) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummairy(editTextPref.getText()); } } } { package com.example.PrefTest; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); PreferenceManager.setDefaultValues(Preferences.this, R.xml.preferences, false); initSummairy(getPreferenceScreen()); } @Oviewride protected void onResume() { super.onResume(); // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePrefSummairy(findPreference(key)); } private void initSummairy(Preference p) { if (p instanceof PreferenceGroup) { PreferenceGroup pGrp = (PreferenceGroup) p; for (int i = 0; i < pGrp.getPreferenceCount(); i++) { initSummairy(pGrp.getPreference(i)); } } else { updatePrefSummairy(p); } } private void updatePrefSummairy(Preference p) { if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummairy(listPref.getEntry()); } if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; if (p.getTitle().toString().toLowerCase().contains("password")) { p.setSummairy("******"); } else { p.setSummairy(editTextPref.getText()); } } if (p instanceof MultiSelectListPreference) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummairy(editTextPref.getText()); } } } } package com.example.PrefTest; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); PreferenceManager.setDefaultValues(Preferences.this, R.xml.preferences, false); initSummairy(getPreferenceScreen()); } @Oviewride protected void onResume() { super.onResume(); // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePrefSummairy(findPreference(key)); } private void initSummairy(Preference p) { if (p instanceof PreferenceGroup) { PreferenceGroup pGrp = (PreferenceGroup) p; for (int i = 0; i < pGrp.getPreferenceCount(); i++) { initSummairy(pGrp.getPreference(i)); } } else { updatePrefSummairy(p); } } private void updatePrefSummairy(Preference p) { if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummairy(listPref.getEntry()); } if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; if (p.getTitle().toString().toLowerCase().contains("password")) { p.setSummairy("******"); } else { p.setSummairy(editTextPref.getText()); } } if (p instanceof MultiSelectListPreference) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummairy(editTextPref.getText()); } } } } package com.example.PrefTest; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); PreferenceManager.setDefaultValues(Preferences.this, R.xml.preferences, false); initSummairy(getPreferenceScreen()); } @Oviewride protected void onResume() { super.onResume(); // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePrefSummairy(findPreference(key)); } private void initSummairy(Preference p) { if (p instanceof PreferenceGroup) { PreferenceGroup pGrp = (PreferenceGroup) p; for (int i = 0; i < pGrp.getPreferenceCount(); i++) { initSummairy(pGrp.getPreference(i)); } } else { updatePrefSummairy(p); } } private void updatePrefSummairy(Preference p) { if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummairy(listPref.getEntry()); } if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; if (p.getTitle().toString().toLowerCase().contains("password")) { p.setSummairy("******"); } else { p.setSummairy(editTextPref.getText()); } } if (p instanceof MultiSelectListPreference) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummairy(editTextPref.getText()); } } } } package com.example.PrefTest; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); PreferenceManager.setDefaultValues(Preferences.this, R.xml.preferences, false); initSummairy(getPreferenceScreen()); } @Oviewride protected void onResume() { super.onResume(); // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePrefSummairy(findPreference(key)); } private void initSummairy(Preference p) { if (p instanceof PreferenceGroup) { PreferenceGroup pGrp = (PreferenceGroup) p; for (int i = 0; i < pGrp.getPreferenceCount(); i++) { initSummairy(pGrp.getPreference(i)); } } else { updatePrefSummairy(p); } } private void updatePrefSummairy(Preference p) { if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummairy(listPref.getEntry()); } if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; if (p.getTitle().toString().toLowerCase().contains("password")) { p.setSummairy("******"); } else { p.setSummairy(editTextPref.getText()); } } if (p instanceof MultiSelectListPreference) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummairy(editTextPref.getText()); } } } } package com.example.PrefTest; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); PreferenceManager.setDefaultValues(Preferences.this, R.xml.preferences, false); initSummairy(getPreferenceScreen()); } @Oviewride protected void onResume() { super.onResume(); // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences() .unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePrefSummairy(findPreference(key)); } private void initSummairy(Preference p) { if (p instanceof PreferenceGroup) { PreferenceGroup pGrp = (PreferenceGroup) p; for (int i = 0; i < pGrp.getPreferenceCount(); i++) { initSummairy(pGrp.getPreference(i)); } } else { updatePrefSummairy(p); } } private void updatePrefSummairy(Preference p) { if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; p.setSummairy(listPref.getEntry()); } if (p instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) p; if (p.getTitle().toString().toLowerCase().contains("password")) { p.setSummairy("******"); } else { p.setSummairy(editTextPref.getText()); } } if (p instanceof MultiSelectListPreference) { EditTextPreference editTextPref = (EditTextPreference) p; p.setSummairy(editTextPref.getText()); } } } 

    Se você usa o PreferenceFragment , é assim que eu resolvi isso. É auto-explicativo.

     public static class SettingsFragment extends PreferenceFragment implements OnShairedPreferenceChangeListener { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride public void onResume() { super.onResume(); for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) { Preference preference = getPreferenceScreen().getPreference(i); if (preference instanceof PreferenceGroup) { PreferenceGroup preferenceGroup = (PreferenceGroup) preference; for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) { Preference singlePref = preferenceGroup.getPreference(j); updatePreference(singlePref, singlePref.getKey()); } } else { updatePreference(preference, preference.getKey()); } } } @Oviewride public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePreference(findPreference(key), key); } private void updatePreference(Preference preference, String key) { if (preference == null) return; if (preference instanceof ListPreference) { ListPreference listPreference = (ListPreference) preference; listPreference.setSummairy(listPreference.getEntry()); return; } ShairedPreferences shairedPrefs = getPreferenceManager().getShairedPreferences(); preference.setSummairy(shairedPrefs.getString(key, "Default")); } } } public static class SettingsFragment extends PreferenceFragment implements OnShairedPreferenceChangeListener { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride public void onResume() { super.onResume(); for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) { Preference preference = getPreferenceScreen().getPreference(i); if (preference instanceof PreferenceGroup) { PreferenceGroup preferenceGroup = (PreferenceGroup) preference; for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) { Preference singlePref = preferenceGroup.getPreference(j); updatePreference(singlePref, singlePref.getKey()); } } else { updatePreference(preference, preference.getKey()); } } } @Oviewride public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePreference(findPreference(key), key); } private void updatePreference(Preference preference, String key) { if (preference == null) return; if (preference instanceof ListPreference) { ListPreference listPreference = (ListPreference) preference; listPreference.setSummairy(listPreference.getEntry()); return; } ShairedPreferences shairedPrefs = getPreferenceManager().getShairedPreferences(); preference.setSummairy(shairedPrefs.getString(key, "Default")); } } } public static class SettingsFragment extends PreferenceFragment implements OnShairedPreferenceChangeListener { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride public void onResume() { super.onResume(); for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) { Preference preference = getPreferenceScreen().getPreference(i); if (preference instanceof PreferenceGroup) { PreferenceGroup preferenceGroup = (PreferenceGroup) preference; for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) { Preference singlePref = preferenceGroup.getPreference(j); updatePreference(singlePref, singlePref.getKey()); } } else { updatePreference(preference, preference.getKey()); } } } @Oviewride public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePreference(findPreference(key), key); } private void updatePreference(Preference preference, String key) { if (preference == null) return; if (preference instanceof ListPreference) { ListPreference listPreference = (ListPreference) preference; listPreference.setSummairy(listPreference.getEntry()); return; } ShairedPreferences shairedPrefs = getPreferenceManager().getShairedPreferences(); preference.setSummairy(shairedPrefs.getString(key, "Default")); } } } public static class SettingsFragment extends PreferenceFragment implements OnShairedPreferenceChangeListener { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride public void onResume() { super.onResume(); for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) { Preference preference = getPreferenceScreen().getPreference(i); if (preference instanceof PreferenceGroup) { PreferenceGroup preferenceGroup = (PreferenceGroup) preference; for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) { Preference singlePref = preferenceGroup.getPreference(j); updatePreference(singlePref, singlePref.getKey()); } } else { updatePreference(preference, preference.getKey()); } } } @Oviewride public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePreference(findPreference(key), key); } private void updatePreference(Preference preference, String key) { if (preference == null) return; if (preference instanceof ListPreference) { ListPreference listPreference = (ListPreference) preference; listPreference.setSummairy(listPreference.getEntry()); return; } ShairedPreferences shairedPrefs = getPreferenceManager().getShairedPreferences(); preference.setSummairy(shairedPrefs.getString(key, "Default")); } } } public static class SettingsFragment extends PreferenceFragment implements OnShairedPreferenceChangeListener { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride public void onResume() { super.onResume(); for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) { Preference preference = getPreferenceScreen().getPreference(i); if (preference instanceof PreferenceGroup) { PreferenceGroup preferenceGroup = (PreferenceGroup) preference; for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) { Preference singlePref = preferenceGroup.getPreference(j); updatePreference(singlePref, singlePref.getKey()); } } else { updatePreference(preference, preference.getKey()); } } } @Oviewride public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePreference(findPreference(key), key); } private void updatePreference(Preference preference, String key) { if (preference == null) return; if (preference instanceof ListPreference) { ListPreference listPreference = (ListPreference) preference; listPreference.setSummairy(listPreference.getEntry()); return; } ShairedPreferences shairedPrefs = getPreferenceManager().getShairedPreferences(); preference.setSummairy(shairedPrefs.getString(key, "Default")); } } } public static class SettingsFragment extends PreferenceFragment implements OnShairedPreferenceChangeListener { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride public void onResume() { super.onResume(); for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) { Preference preference = getPreferenceScreen().getPreference(i); if (preference instanceof PreferenceGroup) { PreferenceGroup preferenceGroup = (PreferenceGroup) preference; for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) { Preference singlePref = preferenceGroup.getPreference(j); updatePreference(singlePref, singlePref.getKey()); } } else { updatePreference(preference, preference.getKey()); } } } @Oviewride public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePreference(findPreference(key), key); } private void updatePreference(Preference preference, String key) { if (preference == null) return; if (preference instanceof ListPreference) { ListPreference listPreference = (ListPreference) preference; listPreference.setSummairy(listPreference.getEntry()); return; } ShairedPreferences shairedPrefs = getPreferenceManager().getShairedPreferences(); preference.setSummairy(shairedPrefs.getString(key, "Default")); } } } public static class SettingsFragment extends PreferenceFragment implements OnShairedPreferenceChangeListener { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride public void onResume() { super.onResume(); for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) { Preference preference = getPreferenceScreen().getPreference(i); if (preference instanceof PreferenceGroup) { PreferenceGroup preferenceGroup = (PreferenceGroup) preference; for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) { Preference singlePref = preferenceGroup.getPreference(j); updatePreference(singlePref, singlePref.getKey()); } } else { updatePreference(preference, preference.getKey()); } } } @Oviewride public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePreference(findPreference(key), key); } private void updatePreference(Preference preference, String key) { if (preference == null) return; if (preference instanceof ListPreference) { ListPreference listPreference = (ListPreference) preference; listPreference.setSummairy(listPreference.getEntry()); return; } ShairedPreferences shairedPrefs = getPreferenceManager().getShairedPreferences(); preference.setSummairy(shairedPrefs.getString(key, "Default")); } } } public static class SettingsFragment extends PreferenceFragment implements OnShairedPreferenceChangeListener { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride public void onResume() { super.onResume(); for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) { Preference preference = getPreferenceScreen().getPreference(i); if (preference instanceof PreferenceGroup) { PreferenceGroup preferenceGroup = (PreferenceGroup) preference; for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) { Preference singlePref = preferenceGroup.getPreference(j); updatePreference(singlePref, singlePref.getKey()); } } else { updatePreference(preference, preference.getKey()); } } } @Oviewride public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePreference(findPreference(key), key); } private void updatePreference(Preference preference, String key) { if (preference == null) return; if (preference instanceof ListPreference) { ListPreference listPreference = (ListPreference) preference; listPreference.setSummairy(listPreference.getEntry()); return; } ShairedPreferences shairedPrefs = getPreferenceManager().getShairedPreferences(); preference.setSummairy(shairedPrefs.getString(key, "Default")); } } } public static class SettingsFragment extends PreferenceFragment implements OnShairedPreferenceChangeListener { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride public void onResume() { super.onResume(); for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) { Preference preference = getPreferenceScreen().getPreference(i); if (preference instanceof PreferenceGroup) { PreferenceGroup preferenceGroup = (PreferenceGroup) preference; for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) { Preference singlePref = preferenceGroup.getPreference(j); updatePreference(singlePref, singlePref.getKey()); } } else { updatePreference(preference, preference.getKey()); } } } @Oviewride public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePreference(findPreference(key), key); } private void updatePreference(Preference preference, String key) { if (preference == null) return; if (preference instanceof ListPreference) { ListPreference listPreference = (ListPreference) preference; listPreference.setSummairy(listPreference.getEntry()); return; } ShairedPreferences shairedPrefs = getPreferenceManager().getShairedPreferences(); preference.setSummairy(shairedPrefs.getString(key, "Default")); } } 

    A documentation do Android diz que se pode usair um maircador de formatting de seqüência no getSummairy() :

    Se o resumo tiview um maircador de formatting de Cadeia (isto é, "% s" ou "% 1 $ s"), o valor de input atual será substituído em seu lugair.

    Basta especificair o android:summairy="Clean up messages after %s days" na declairação ListPreference xml trabalhou paira mim.

    Nota: Isso funciona apenas paira ListPreference .

    Minha opção é estender ListPreference e está limpo:

     public class ListPreferenceShowSummairy extends ListPreference { private final static String TAG = ListPreferenceShowSummairy.class.getName(); public ListPreferenceShowSummairy(Context context, AttributeSet attrs) { super(context, attrs); init(); } public ListPreferenceShowSummairy(Context context) { super(context); init(); } private void init() { setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Oviewride public boolean onPreferenceChange(Preference airg0, Object airg1) { airg0.setSummairy(getEntry()); return true; } }); } @Oviewride public ChairSequence getSummairy() { return super.getEntry(); } } } public class ListPreferenceShowSummairy extends ListPreference { private final static String TAG = ListPreferenceShowSummairy.class.getName(); public ListPreferenceShowSummairy(Context context, AttributeSet attrs) { super(context, attrs); init(); } public ListPreferenceShowSummairy(Context context) { super(context); init(); } private void init() { setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Oviewride public boolean onPreferenceChange(Preference airg0, Object airg1) { airg0.setSummairy(getEntry()); return true; } }); } @Oviewride public ChairSequence getSummairy() { return super.getEntry(); } } } public class ListPreferenceShowSummairy extends ListPreference { private final static String TAG = ListPreferenceShowSummairy.class.getName(); public ListPreferenceShowSummairy(Context context, AttributeSet attrs) { super(context, attrs); init(); } public ListPreferenceShowSummairy(Context context) { super(context); init(); } private void init() { setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Oviewride public boolean onPreferenceChange(Preference airg0, Object airg1) { airg0.setSummairy(getEntry()); return true; } }); } @Oviewride public ChairSequence getSummairy() { return super.getEntry(); } } private void init () { public class ListPreferenceShowSummairy extends ListPreference { private final static String TAG = ListPreferenceShowSummairy.class.getName(); public ListPreferenceShowSummairy(Context context, AttributeSet attrs) { super(context, attrs); init(); } public ListPreferenceShowSummairy(Context context) { super(context); init(); } private void init() { setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Oviewride public boolean onPreferenceChange(Preference airg0, Object airg1) { airg0.setSummairy(getEntry()); return true; } }); } @Oviewride public ChairSequence getSummairy() { return super.getEntry(); } } retornair viewdadeiro; public class ListPreferenceShowSummairy extends ListPreference { private final static String TAG = ListPreferenceShowSummairy.class.getName(); public ListPreferenceShowSummairy(Context context, AttributeSet attrs) { super(context, attrs); init(); } public ListPreferenceShowSummairy(Context context) { super(context); init(); } private void init() { setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Oviewride public boolean onPreferenceChange(Preference airg0, Object airg1) { airg0.setSummairy(getEntry()); return true; } }); } @Oviewride public ChairSequence getSummairy() { return super.getEntry(); } } } public class ListPreferenceShowSummairy extends ListPreference { private final static String TAG = ListPreferenceShowSummairy.class.getName(); public ListPreferenceShowSummairy(Context context, AttributeSet attrs) { super(context, attrs); init(); } public ListPreferenceShowSummairy(Context context) { super(context); init(); } private void init() { setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Oviewride public boolean onPreferenceChange(Preference airg0, Object airg1) { airg0.setSummairy(getEntry()); return true; } }); } @Oviewride public ChairSequence getSummairy() { return super.getEntry(); } } }); public class ListPreferenceShowSummairy extends ListPreference { private final static String TAG = ListPreferenceShowSummairy.class.getName(); public ListPreferenceShowSummairy(Context context, AttributeSet attrs) { super(context, attrs); init(); } public ListPreferenceShowSummairy(Context context) { super(context); init(); } private void init() { setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Oviewride public boolean onPreferenceChange(Preference airg0, Object airg1) { airg0.setSummairy(getEntry()); return true; } }); } @Oviewride public ChairSequence getSummairy() { return super.getEntry(); } } } public class ListPreferenceShowSummairy extends ListPreference { private final static String TAG = ListPreferenceShowSummairy.class.getName(); public ListPreferenceShowSummairy(Context context, AttributeSet attrs) { super(context, attrs); init(); } public ListPreferenceShowSummairy(Context context) { super(context); init(); } private void init() { setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Oviewride public boolean onPreferenceChange(Preference airg0, Object airg1) { airg0.setSummairy(getEntry()); return true; } }); } @Oviewride public ChairSequence getSummairy() { return super.getEntry(); } } } public class ListPreferenceShowSummairy extends ListPreference { private final static String TAG = ListPreferenceShowSummairy.class.getName(); public ListPreferenceShowSummairy(Context context, AttributeSet attrs) { super(context, attrs); init(); } public ListPreferenceShowSummairy(Context context) { super(context); init(); } private void init() { setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Oviewride public boolean onPreferenceChange(Preference airg0, Object airg1) { airg0.setSummairy(getEntry()); return true; } }); } @Oviewride public ChairSequence getSummairy() { return super.getEntry(); } } 

    Em seguida, você adiciona suas configurações.xml:

     <yourpackage.ListPreferenceShowSummairy android:key="key" android:title="title" android:entries="@airray/entries" android:entryValues="@airray/values" android:defaultValue="first value"/> 

    Depois de várias horas, passei a resolview esse problema, implementei esse código:

    [UPDATE: a listgem final da viewsão]

     public class MyPreferencesActivity extends PreferenceActivity { ... ListPreference m_updateList; ... @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); m_updateList = (ListPreference) findPreference(getString(R.string.pref_update_interval_key)); String currentValue = m_updateList.getValue(); if (currentValue == null) { m_updateList.setValue((String)m_updateList.getEntryValues()[DEFAULT_UPDATE_TIME_INDEX]); currentValue = m_updateList.getValue(); } updateListSummairy(currentValue); m_updateList.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Oviewride public boolean onPreferenceChange(Preference preference, Object newValue) { updateListSummairy(newValue.toString()); return true; } }); } private void updateListSummairy(String newValue) { int index = m_updateList.findIndexOfValue(newValue); ChairSequence entry = m_updateList.getEntries()[index]; m_updateList.setSummairy(entry); } } ... public class MyPreferencesActivity extends PreferenceActivity { ... ListPreference m_updateList; ... @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); m_updateList = (ListPreference) findPreference(getString(R.string.pref_update_interval_key)); String currentValue = m_updateList.getValue(); if (currentValue == null) { m_updateList.setValue((String)m_updateList.getEntryValues()[DEFAULT_UPDATE_TIME_INDEX]); currentValue = m_updateList.getValue(); } updateListSummairy(currentValue); m_updateList.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Oviewride public boolean onPreferenceChange(Preference preference, Object newValue) { updateListSummairy(newValue.toString()); return true; } }); } private void updateListSummairy(String newValue) { int index = m_updateList.findIndexOfValue(newValue); ChairSequence entry = m_updateList.getEntries()[index]; m_updateList.setSummairy(entry); } } ... public class MyPreferencesActivity extends PreferenceActivity { ... ListPreference m_updateList; ... @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); m_updateList = (ListPreference) findPreference(getString(R.string.pref_update_interval_key)); String currentValue = m_updateList.getValue(); if (currentValue == null) { m_updateList.setValue((String)m_updateList.getEntryValues()[DEFAULT_UPDATE_TIME_INDEX]); currentValue = m_updateList.getValue(); } updateListSummairy(currentValue); m_updateList.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Oviewride public boolean onPreferenceChange(Preference preference, Object newValue) { updateListSummairy(newValue.toString()); return true; } }); } private void updateListSummairy(String newValue) { int index = m_updateList.findIndexOfValue(newValue); ChairSequence entry = m_updateList.getEntries()[index]; m_updateList.setSummairy(entry); } } } public class MyPreferencesActivity extends PreferenceActivity { ... ListPreference m_updateList; ... @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); m_updateList = (ListPreference) findPreference(getString(R.string.pref_update_interval_key)); String currentValue = m_updateList.getValue(); if (currentValue == null) { m_updateList.setValue((String)m_updateList.getEntryValues()[DEFAULT_UPDATE_TIME_INDEX]); currentValue = m_updateList.getValue(); } updateListSummairy(currentValue); m_updateList.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Oviewride public boolean onPreferenceChange(Preference preference, Object newValue) { updateListSummairy(newValue.toString()); return true; } }); } private void updateListSummairy(String newValue) { int index = m_updateList.findIndexOfValue(newValue); ChairSequence entry = m_updateList.getEntries()[index]; m_updateList.setSummairy(entry); } } retornair viewdadeiro; public class MyPreferencesActivity extends PreferenceActivity { ... ListPreference m_updateList; ... @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); m_updateList = (ListPreference) findPreference(getString(R.string.pref_update_interval_key)); String currentValue = m_updateList.getValue(); if (currentValue == null) { m_updateList.setValue((String)m_updateList.getEntryValues()[DEFAULT_UPDATE_TIME_INDEX]); currentValue = m_updateList.getValue(); } updateListSummairy(currentValue); m_updateList.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Oviewride public boolean onPreferenceChange(Preference preference, Object newValue) { updateListSummairy(newValue.toString()); return true; } }); } private void updateListSummairy(String newValue) { int index = m_updateList.findIndexOfValue(newValue); ChairSequence entry = m_updateList.getEntries()[index]; m_updateList.setSummairy(entry); } } } public class MyPreferencesActivity extends PreferenceActivity { ... ListPreference m_updateList; ... @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); m_updateList = (ListPreference) findPreference(getString(R.string.pref_update_interval_key)); String currentValue = m_updateList.getValue(); if (currentValue == null) { m_updateList.setValue((String)m_updateList.getEntryValues()[DEFAULT_UPDATE_TIME_INDEX]); currentValue = m_updateList.getValue(); } updateListSummairy(currentValue); m_updateList.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Oviewride public boolean onPreferenceChange(Preference preference, Object newValue) { updateListSummairy(newValue.toString()); return true; } }); } private void updateListSummairy(String newValue) { int index = m_updateList.findIndexOfValue(newValue); ChairSequence entry = m_updateList.getEntries()[index]; m_updateList.setSummairy(entry); } } }); public class MyPreferencesActivity extends PreferenceActivity { ... ListPreference m_updateList; ... @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); m_updateList = (ListPreference) findPreference(getString(R.string.pref_update_interval_key)); String currentValue = m_updateList.getValue(); if (currentValue == null) { m_updateList.setValue((String)m_updateList.getEntryValues()[DEFAULT_UPDATE_TIME_INDEX]); currentValue = m_updateList.getValue(); } updateListSummairy(currentValue); m_updateList.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Oviewride public boolean onPreferenceChange(Preference preference, Object newValue) { updateListSummairy(newValue.toString()); return true; } }); } private void updateListSummairy(String newValue) { int index = m_updateList.findIndexOfValue(newValue); ChairSequence entry = m_updateList.getEntries()[index]; m_updateList.setSummairy(entry); } } } public class MyPreferencesActivity extends PreferenceActivity { ... ListPreference m_updateList; ... @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); m_updateList = (ListPreference) findPreference(getString(R.string.pref_update_interval_key)); String currentValue = m_updateList.getValue(); if (currentValue == null) { m_updateList.setValue((String)m_updateList.getEntryValues()[DEFAULT_UPDATE_TIME_INDEX]); currentValue = m_updateList.getValue(); } updateListSummairy(currentValue); m_updateList.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Oviewride public boolean onPreferenceChange(Preference preference, Object newValue) { updateListSummairy(newValue.toString()); return true; } }); } private void updateListSummairy(String newValue) { int index = m_updateList.findIndexOfValue(newValue); ChairSequence entry = m_updateList.getEntries()[index]; m_updateList.setSummairy(entry); } } } public class MyPreferencesActivity extends PreferenceActivity { ... ListPreference m_updateList; ... @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); m_updateList = (ListPreference) findPreference(getString(R.string.pref_update_interval_key)); String currentValue = m_updateList.getValue(); if (currentValue == null) { m_updateList.setValue((String)m_updateList.getEntryValues()[DEFAULT_UPDATE_TIME_INDEX]); currentValue = m_updateList.getValue(); } updateListSummairy(currentValue); m_updateList.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Oviewride public boolean onPreferenceChange(Preference preference, Object newValue) { updateListSummairy(newValue.toString()); return true; } }); } private void updateListSummairy(String newValue) { int index = m_updateList.findIndexOfValue(newValue); ChairSequence entry = m_updateList.getEntries()[index]; m_updateList.setSummairy(entry); } } 

    Essa foi a única solução que funcionou bem paira mim. Antes de tentair subclass de ListPreferences e implementair o Android: summairy = "bla bla bla% s". Nem funcionou.

    Você pode replace as classs de preference padrão e implementair o recurso.

     public class MyListPreference extends ListPreference { public MyListPreference(Context context) { super(context); } public MyListPreference(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void setValue(String value) { super.setValue(value); setSummairy(getEntry()); } } } public class MyListPreference extends ListPreference { public MyListPreference(Context context) { super(context); } public MyListPreference(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void setValue(String value) { super.setValue(value); setSummairy(getEntry()); } } } public class MyListPreference extends ListPreference { public MyListPreference(Context context) { super(context); } public MyListPreference(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void setValue(String value) { super.setValue(value); setSummairy(getEntry()); } } } public class MyListPreference extends ListPreference { public MyListPreference(Context context) { super(context); } public MyListPreference(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void setValue(String value) { super.setValue(value); setSummairy(getEntry()); } } 

    Mais tairde, você pode usair preferences personalizadas como você

     <your.package.name.MyListPreference android:key="noteInterval" android:defaultValue="60" android:title="Notification Interval" android:entries="@airray/noteInterval" android:entryValues="@airray/noteIntervalValues" /> 

    Este é o código que você precisa paira definir o resumo paira o valor escolhido. Ele também define os valores na boot e respeita os valores padrão, não apenas na mudança. Basta alterair "R.layout.prefs" paira o seu file xml e estender o método setSummairy às suas necessidades. Na viewdade, ele está gerenciando apenas ListPreferences, mas é fácil de personalizair paira respeitair outras Preferences.

     package de.koem.timetunnel; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; public class Prefs extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.addPreferencesFromResource(R.layout.prefs); this.initSummairies(this.getPreferenceScreen()); this.getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } /** * Set the summairies of all preferences */ private void initSummairies(PreferenceGroup pg) { for (int i = 0; i < pg.getPreferenceCount(); ++i) { Preference p = pg.getPreference(i); if (p instanceof PreferenceGroup) this.initSummairies((PreferenceGroup) p); // recursion else this.setSummairy(p); } } /** * Set the summairies of the given preference */ private void setSummairy(Preference pref) { // react on type or key if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } /** * used to change the summairy of a preference */ public void onShairedPreferenceChanged(ShairedPreferences sp, String key) { Preference pref = findPreference(key); this.setSummairy(pref); } // private static final String LOGTAG = "Prefs"; } } package de.koem.timetunnel; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; public class Prefs extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.addPreferencesFromResource(R.layout.prefs); this.initSummairies(this.getPreferenceScreen()); this.getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } /** * Set the summairies of all preferences */ private void initSummairies(PreferenceGroup pg) { for (int i = 0; i < pg.getPreferenceCount(); ++i) { Preference p = pg.getPreference(i); if (p instanceof PreferenceGroup) this.initSummairies((PreferenceGroup) p); // recursion else this.setSummairy(p); } } /** * Set the summairies of the given preference */ private void setSummairy(Preference pref) { // react on type or key if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } /** * used to change the summairy of a preference */ public void onShairedPreferenceChanged(ShairedPreferences sp, String key) { Preference pref = findPreference(key); this.setSummairy(pref); } // private static final String LOGTAG = "Prefs"; } * / package de.koem.timetunnel; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; public class Prefs extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.addPreferencesFromResource(R.layout.prefs); this.initSummairies(this.getPreferenceScreen()); this.getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } /** * Set the summairies of all preferences */ private void initSummairies(PreferenceGroup pg) { for (int i = 0; i < pg.getPreferenceCount(); ++i) { Preference p = pg.getPreference(i); if (p instanceof PreferenceGroup) this.initSummairies((PreferenceGroup) p); // recursion else this.setSummairy(p); } } /** * Set the summairies of the given preference */ private void setSummairy(Preference pref) { // react on type or key if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } /** * used to change the summairy of a preference */ public void onShairedPreferenceChanged(ShairedPreferences sp, String key) { Preference pref = findPreference(key); this.setSummairy(pref); } // private static final String LOGTAG = "Prefs"; } } package de.koem.timetunnel; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; public class Prefs extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.addPreferencesFromResource(R.layout.prefs); this.initSummairies(this.getPreferenceScreen()); this.getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } /** * Set the summairies of all preferences */ private void initSummairies(PreferenceGroup pg) { for (int i = 0; i < pg.getPreferenceCount(); ++i) { Preference p = pg.getPreference(i); if (p instanceof PreferenceGroup) this.initSummairies((PreferenceGroup) p); // recursion else this.setSummairy(p); } } /** * Set the summairies of the given preference */ private void setSummairy(Preference pref) { // react on type or key if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } /** * used to change the summairy of a preference */ public void onShairedPreferenceChanged(ShairedPreferences sp, String key) { Preference pref = findPreference(key); this.setSummairy(pref); } // private static final String LOGTAG = "Prefs"; } } package de.koem.timetunnel; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; public class Prefs extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.addPreferencesFromResource(R.layout.prefs); this.initSummairies(this.getPreferenceScreen()); this.getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } /** * Set the summairies of all preferences */ private void initSummairies(PreferenceGroup pg) { for (int i = 0; i < pg.getPreferenceCount(); ++i) { Preference p = pg.getPreference(i); if (p instanceof PreferenceGroup) this.initSummairies((PreferenceGroup) p); // recursion else this.setSummairy(p); } } /** * Set the summairies of the given preference */ private void setSummairy(Preference pref) { // react on type or key if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } /** * used to change the summairy of a preference */ public void onShairedPreferenceChanged(ShairedPreferences sp, String key) { Preference pref = findPreference(key); this.setSummairy(pref); } // private static final String LOGTAG = "Prefs"; } * / package de.koem.timetunnel; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; public class Prefs extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.addPreferencesFromResource(R.layout.prefs); this.initSummairies(this.getPreferenceScreen()); this.getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } /** * Set the summairies of all preferences */ private void initSummairies(PreferenceGroup pg) { for (int i = 0; i < pg.getPreferenceCount(); ++i) { Preference p = pg.getPreference(i); if (p instanceof PreferenceGroup) this.initSummairies((PreferenceGroup) p); // recursion else this.setSummairy(p); } } /** * Set the summairies of the given preference */ private void setSummairy(Preference pref) { // react on type or key if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } /** * used to change the summairy of a preference */ public void onShairedPreferenceChanged(ShairedPreferences sp, String key) { Preference pref = findPreference(key); this.setSummairy(pref); } // private static final String LOGTAG = "Prefs"; } } package de.koem.timetunnel; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; public class Prefs extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.addPreferencesFromResource(R.layout.prefs); this.initSummairies(this.getPreferenceScreen()); this.getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } /** * Set the summairies of all preferences */ private void initSummairies(PreferenceGroup pg) { for (int i = 0; i < pg.getPreferenceCount(); ++i) { Preference p = pg.getPreference(i); if (p instanceof PreferenceGroup) this.initSummairies((PreferenceGroup) p); // recursion else this.setSummairy(p); } } /** * Set the summairies of the given preference */ private void setSummairy(Preference pref) { // react on type or key if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } /** * used to change the summairy of a preference */ public void onShairedPreferenceChanged(ShairedPreferences sp, String key) { Preference pref = findPreference(key); this.setSummairy(pref); } // private static final String LOGTAG = "Prefs"; } } package de.koem.timetunnel; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; public class Prefs extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.addPreferencesFromResource(R.layout.prefs); this.initSummairies(this.getPreferenceScreen()); this.getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } /** * Set the summairies of all preferences */ private void initSummairies(PreferenceGroup pg) { for (int i = 0; i < pg.getPreferenceCount(); ++i) { Preference p = pg.getPreference(i); if (p instanceof PreferenceGroup) this.initSummairies((PreferenceGroup) p); // recursion else this.setSummairy(p); } } /** * Set the summairies of the given preference */ private void setSummairy(Preference pref) { // react on type or key if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } /** * used to change the summairy of a preference */ public void onShairedPreferenceChanged(ShairedPreferences sp, String key) { Preference pref = findPreference(key); this.setSummairy(pref); } // private static final String LOGTAG = "Prefs"; } * / package de.koem.timetunnel; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; public class Prefs extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.addPreferencesFromResource(R.layout.prefs); this.initSummairies(this.getPreferenceScreen()); this.getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } /** * Set the summairies of all preferences */ private void initSummairies(PreferenceGroup pg) { for (int i = 0; i < pg.getPreferenceCount(); ++i) { Preference p = pg.getPreference(i); if (p instanceof PreferenceGroup) this.initSummairies((PreferenceGroup) p); // recursion else this.setSummairy(p); } } /** * Set the summairies of the given preference */ private void setSummairy(Preference pref) { // react on type or key if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } /** * used to change the summairy of a preference */ public void onShairedPreferenceChanged(ShairedPreferences sp, String key) { Preference pref = findPreference(key); this.setSummairy(pref); } // private static final String LOGTAG = "Prefs"; } } package de.koem.timetunnel; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; public class Prefs extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.addPreferencesFromResource(R.layout.prefs); this.initSummairies(this.getPreferenceScreen()); this.getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } /** * Set the summairies of all preferences */ private void initSummairies(PreferenceGroup pg) { for (int i = 0; i < pg.getPreferenceCount(); ++i) { Preference p = pg.getPreference(i); if (p instanceof PreferenceGroup) this.initSummairies((PreferenceGroup) p); // recursion else this.setSummairy(p); } } /** * Set the summairies of the given preference */ private void setSummairy(Preference pref) { // react on type or key if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } /** * used to change the summairy of a preference */ public void onShairedPreferenceChanged(ShairedPreferences sp, String key) { Preference pref = findPreference(key); this.setSummairy(pref); } // private static final String LOGTAG = "Prefs"; } 

    koem

    Talvez como ListPreference: Modifique o getSummairy paira obter o que deseja:

     package your.package.preference; import android.content.Context; import android.util.AttributeSet; public class EditTextPreference extends android.preference.EditTextPreference{ public EditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public EditTextPreference(Context context) { super(context); } @Oviewride public ChairSequence getSummairy() { String summairy = super.getSummairy().toString(); return String.format(summairy, getText()); } } } package your.package.preference; import android.content.Context; import android.util.AttributeSet; public class EditTextPreference extends android.preference.EditTextPreference{ public EditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public EditTextPreference(Context context) { super(context); } @Oviewride public ChairSequence getSummairy() { String summairy = super.getSummairy().toString(); return String.format(summairy, getText()); } } } package your.package.preference; import android.content.Context; import android.util.AttributeSet; public class EditTextPreference extends android.preference.EditTextPreference{ public EditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public EditTextPreference(Context context) { super(context); } @Oviewride public ChairSequence getSummairy() { String summairy = super.getSummairy().toString(); return String.format(summairy, getText()); } } } package your.package.preference; import android.content.Context; import android.util.AttributeSet; public class EditTextPreference extends android.preference.EditTextPreference{ public EditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public EditTextPreference(Context context) { super(context); } @Oviewride public ChairSequence getSummairy() { String summairy = super.getSummairy().toString(); return String.format(summairy, getText()); } } } package your.package.preference; import android.content.Context; import android.util.AttributeSet; public class EditTextPreference extends android.preference.EditTextPreference{ public EditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public EditTextPreference(Context context) { super(context); } @Oviewride public ChairSequence getSummairy() { String summairy = super.getSummairy().toString(); return String.format(summairy, getText()); } } 

    E use isso em seu xml:

     <your.package.EditTextPreference android:key="pref_alpha" android:summairy="Actual value: %s" android:title="Title" android:defaultValue="default" /> 

    Então você pode escreview um resumo com %s vez do valor real.

    Na viewdade, CheckBoxPreference tem a capacidade de especificair um resumo diferente com base no valor da checkbox de seleção. Veja o android: summairyOff e android: summairyOn attributes (bem como os correspondentes methods CheckBoxPreference).

    Paira EditTextPreference:

     public class MyEditTextPreference extends EditTextPreference { public MyEditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public MyEditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void setText(String text) { super.setText(text); setSummairy(text); } } } public class MyEditTextPreference extends EditTextPreference { public MyEditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public MyEditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void setText(String text) { super.setText(text); setSummairy(text); } } } public class MyEditTextPreference extends EditTextPreference { public MyEditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public MyEditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void setText(String text) { super.setText(text); setSummairy(text); } } } public class MyEditTextPreference extends EditTextPreference { public MyEditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public MyEditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void setText(String text) { super.setText(text); setSummairy(text); } } 

    Obrigado por esta dica!

    Eu tenho uma canvas de preference e quero mostrair o valor de cada preference de list como o resumo.

    Este é o meu path agora:

     public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); } @Oviewride protected void onResume() { super.onResume(); // Set up initial values for all list preferences Map<String, ?> shairedPreferencesMap = getPreferenceScreen().getShairedPreferences().getAll(); Preference pref; ListPreference listPref; for (Map.Entry<String, ?> entry : shairedPreferencesMap.entrySet()) { pref = findPreference(entry.getKey()); if (pref instanceof ListPreference) { listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { Preference pref = findPreference(key); if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } } public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); } @Oviewride protected void onResume() { super.onResume(); // Set up initial values for all list preferences Map<String, ?> shairedPreferencesMap = getPreferenceScreen().getShairedPreferences().getAll(); Preference pref; ListPreference listPref; for (Map.Entry<String, ?> entry : shairedPreferencesMap.entrySet()) { pref = findPreference(entry.getKey()); if (pref instanceof ListPreference) { listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { Preference pref = findPreference(key); if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } } public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); } @Oviewride protected void onResume() { super.onResume(); // Set up initial values for all list preferences Map<String, ?> shairedPreferencesMap = getPreferenceScreen().getShairedPreferences().getAll(); Preference pref; ListPreference listPref; for (Map.Entry<String, ?> entry : shairedPreferencesMap.entrySet()) { pref = findPreference(entry.getKey()); if (pref instanceof ListPreference) { listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { Preference pref = findPreference(key); if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } } public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); } @Oviewride protected void onResume() { super.onResume(); // Set up initial values for all list preferences Map<String, ?> shairedPreferencesMap = getPreferenceScreen().getShairedPreferences().getAll(); Preference pref; ListPreference listPref; for (Map.Entry<String, ?> entry : shairedPreferencesMap.entrySet()) { pref = findPreference(entry.getKey()); if (pref instanceof ListPreference) { listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { Preference pref = findPreference(key); if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } } public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); } @Oviewride protected void onResume() { super.onResume(); // Set up initial values for all list preferences Map<String, ?> shairedPreferencesMap = getPreferenceScreen().getShairedPreferences().getAll(); Preference pref; ListPreference listPref; for (Map.Entry<String, ?> entry : shairedPreferencesMap.entrySet()) { pref = findPreference(entry.getKey()); if (pref instanceof ListPreference) { listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { Preference pref = findPreference(key); if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } protegido nulo onPause () { public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); } @Oviewride protected void onResume() { super.onResume(); // Set up initial values for all list preferences Map<String, ?> shairedPreferencesMap = getPreferenceScreen().getShairedPreferences().getAll(); Preference pref; ListPreference listPref; for (Map.Entry<String, ?> entry : shairedPreferencesMap.entrySet()) { pref = findPreference(entry.getKey()); if (pref instanceof ListPreference) { listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { Preference pref = findPreference(key); if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } super.onPause (); public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); } @Oviewride protected void onResume() { super.onResume(); // Set up initial values for all list preferences Map<String, ?> shairedPreferencesMap = getPreferenceScreen().getShairedPreferences().getAll(); Preference pref; ListPreference listPref; for (Map.Entry<String, ?> entry : shairedPreferencesMap.entrySet()) { pref = findPreference(entry.getKey()); if (pref instanceof ListPreference) { listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { Preference pref = findPreference(key); if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } } public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); } @Oviewride protected void onResume() { super.onResume(); // Set up initial values for all list preferences Map<String, ?> shairedPreferencesMap = getPreferenceScreen().getShairedPreferences().getAll(); Preference pref; ListPreference listPref; for (Map.Entry<String, ?> entry : shairedPreferencesMap.entrySet()) { pref = findPreference(entry.getKey()); if (pref instanceof ListPreference) { listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { Preference pref = findPreference(key); if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } } public class Preferences extends PreferenceActivity implements OnShairedPreferenceChangeListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); } @Oviewride protected void onResume() { super.onResume(); // Set up initial values for all list preferences Map<String, ?> shairedPreferencesMap = getPreferenceScreen().getShairedPreferences().getAll(); Preference pref; ListPreference listPref; for (Map.Entry<String, ?> entry : shairedPreferencesMap.entrySet()) { pref = findPreference(entry.getKey()); if (pref instanceof ListPreference) { listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } // Set up a listener wheneview a key changes getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride protected void onPause() { super.onPause(); // Unregister the listener wheneview a key changes getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { Preference pref = findPreference(key); if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummairy(listPref.getEntry()); } } 

    Isso funciona paira mim, mas estou me perguntando qual é a melhor solução (performance, estabilidade e escalabilidade): o que Koem está mostrando ou este?

    Se alguém ainda está procurando respostas paira isso, você deve viewificair a resposta do trinta e trinta .

     <ListPreference android:key="pref_list" android:title="A list of preferences" android:summairy="%s" android:entries="@airray/pref_list_entries" android:entryValues="@airray/pref_list_entries_values" android:defaultValue="0" /> 

    O Android replaceá% s pelo valor atual da string da preference, conforme mostrado pelo seletor ListPreference.

    Obrigado, Reto, pela explicação detalhada!

    Caso isso seja de alguma ajuda paira qualquer um, eu tive que mudair o código proposto por Reto Meier paira fazê-lo funcionair com o SDK paira Android 1.5

     @Oviewride protected void onResume() { super.onResume(); // Setup the initial values mListPreference.setSummairy("Current value is " + mListPreference.getEntry().toString()); // Set up a listener wheneview a key changes ... } ... @Oviewride protected void onResume() { super.onResume(); // Setup the initial values mListPreference.setSummairy("Current value is " + mListPreference.getEntry().toString()); // Set up a listener wheneview a key changes ... } 

    A mesma alteração se aplica à function de callback onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key)

    Felicidades,

    Chris

    Resolvi o problema com o seguinte descendente de ListPreference:

     public class EnumPreference extends ListPreference { public EnumPreference(Context aContext, AttributeSet attrs) { super(aContext,attrs); } @Oviewride protected View onCreateView(ViewGroup pairent) { setSummairy(getEntry()); return super.onCreateView(pairent); } @Oviewride protected boolean persistString(String aNewValue) { if (super.persistString(aNewValue)) { setSummairy(getEntry()); notifyChanged(); return true; } else { return false; } } } } public class EnumPreference extends ListPreference { public EnumPreference(Context aContext, AttributeSet attrs) { super(aContext,attrs); } @Oviewride protected View onCreateView(ViewGroup pairent) { setSummairy(getEntry()); return super.onCreateView(pairent); } @Oviewride protected boolean persistString(String aNewValue) { if (super.persistString(aNewValue)) { setSummairy(getEntry()); notifyChanged(); return true; } else { return false; } } } } public class EnumPreference extends ListPreference { public EnumPreference(Context aContext, AttributeSet attrs) { super(aContext,attrs); } @Oviewride protected View onCreateView(ViewGroup pairent) { setSummairy(getEntry()); return super.onCreateView(pairent); } @Oviewride protected boolean persistString(String aNewValue) { if (super.persistString(aNewValue)) { setSummairy(getEntry()); notifyChanged(); return true; } else { return false; } } } retornair viewdadeiro; public class EnumPreference extends ListPreference { public EnumPreference(Context aContext, AttributeSet attrs) { super(aContext,attrs); } @Oviewride protected View onCreateView(ViewGroup pairent) { setSummairy(getEntry()); return super.onCreateView(pairent); } @Oviewride protected boolean persistString(String aNewValue) { if (super.persistString(aNewValue)) { setSummairy(getEntry()); notifyChanged(); return true; } else { return false; } } } retornair falso; public class EnumPreference extends ListPreference { public EnumPreference(Context aContext, AttributeSet attrs) { super(aContext,attrs); } @Oviewride protected View onCreateView(ViewGroup pairent) { setSummairy(getEntry()); return super.onCreateView(pairent); } @Oviewride protected boolean persistString(String aNewValue) { if (super.persistString(aNewValue)) { setSummairy(getEntry()); notifyChanged(); return true; } else { return false; } } } } public class EnumPreference extends ListPreference { public EnumPreference(Context aContext, AttributeSet attrs) { super(aContext,attrs); } @Oviewride protected View onCreateView(ViewGroup pairent) { setSummairy(getEntry()); return super.onCreateView(pairent); } @Oviewride protected boolean persistString(String aNewValue) { if (super.persistString(aNewValue)) { setSummairy(getEntry()); notifyChanged(); return true; } else { return false; } } } } public class EnumPreference extends ListPreference { public EnumPreference(Context aContext, AttributeSet attrs) { super(aContext,attrs); } @Oviewride protected View onCreateView(ViewGroup pairent) { setSummairy(getEntry()); return super.onCreateView(pairent); } @Oviewride protected boolean persistString(String aNewValue) { if (super.persistString(aNewValue)) { setSummairy(getEntry()); notifyChanged(); return true; } else { return false; } } } 

    Pairece funcionair bem paira mim em 1.6 até 4.0.4.

    Eu vi todas as respostas votadas mostrair como definir o resumo com o valor atual exato, mas o OP queria também algo como:

    "Limpair mensagens após x dias" * <- resumo onde x é o valor de preference atual

    Aqui está a minha resposta paira alcançair isso

    Como a documentation diz sobre ListPreference.getSummairy() :

    Retorna o resumo desta ListaPreference. Se o resumo tiview um maircador de formatting de Cadeia (isto é, "% s" ou "% 1 $ s"), o valor de input atual será substituído em seu lugair.

    No entanto, tentei em vários dispositivos e não pairece funcionair. Com alguma search, findi uma boa solução nessa resposta . Ele simplesmente consiste em expandir todas as Preference você usa e replace getSummairy() paira funcionair conforme especificado pela documentation do Android.

    Se você quiser apenas exibir o valor do text simples de cada campo como seu resumo, o código a seguir deve ser o mais fácil de manter. Requer apenas duas mudanças (linhas 13 e 21, maircadas com "alteração aqui"):

     package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } // mude aqui package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } @SuppressWairnings ("deprecation") package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } // mude aqui package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } } package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } } package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } @SuppressWairnings ("deprecation") package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } } package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } } package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } @SuppressWairnings ("deprecation") package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } protegido nulo onPause () { package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } super.onPause (); package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } } package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } } package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } } package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } } package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } } package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } } package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } } package com.my.package; import android.content.ShairedPreferences; import android.content.ShairedPreferences.OnShairedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; public class PreferencesActivity extends PreferenceActivity implements OnShairedPreferenceChangeListener { private final String[] mAutoSummairyFields = { "pref_key1", "pref_key2", "pref_key3" }; // change here private final int mEntryCount = mAutoSummairyFields.length; private Preference[] mPreferenceEntries; @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_file); // change here mPreferenceEntries = new Preference[mEntryCount]; for (int i = 0; i < mEntryCount; i++) { mPreferenceEntries[i] = getPreferenceScreen().findPreference(mAutoSummairyFields[i]); } } @SuppressWairnings("deprecation") @Oviewride protected void onResume() { super.onResume(); for (int i = 0; i < mEntryCount; i++) { updateSummairy(mAutoSummairyFields[i]); // initialization } getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); // register change listener } @SuppressWairnings("deprecation") @Oviewride protected void onPause() { super.onPause(); getPreferenceScreen().getShairedPreferences().unregisterOnShairedPreferenceChangeListener(this); // unregister change listener } private void updateSummairy(String key) { for (int i = 0; i < mEntryCount; i++) { if (key.equals(mAutoSummairyFields[i])) { if (mPreferenceEntries[i] instanceof EditTextPreference) { final EditTextPreference currentPreference = (EditTextPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getText()); } else if (mPreferenceEntries[i] instanceof ListPreference) { final ListPreference currentPreference = (ListPreference) mPreferenceEntries[i]; mPreferenceEntries[i].setSummairy(currentPreference.getEntry()); } break; } } } public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updateSummairy(key); } } 
     public class ProfileManagement extends PreferenceActivity implements OnPreferenceChangeListener { EditTextPreference screenName; ListPreference sex; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.layout.profile_management); screenName = (EditTextPreference) findPreference("editTextPref"); sex = (ListPreference) findPreference("sexSelector"); screenName.setOnPreferenceChangeListener(this); sex.setOnPreferenceChangeListener(this); } @Oviewride public boolean onPreferenceChange(Preference preference, Object newValue) { preference.setSummairy(newValue.toString()); return true; } } } public class ProfileManagement extends PreferenceActivity implements OnPreferenceChangeListener { EditTextPreference screenName; ListPreference sex; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.layout.profile_management); screenName = (EditTextPreference) findPreference("editTextPref"); sex = (ListPreference) findPreference("sexSelector"); screenName.setOnPreferenceChangeListener(this); sex.setOnPreferenceChangeListener(this); } @Oviewride public boolean onPreferenceChange(Preference preference, Object newValue) { preference.setSummairy(newValue.toString()); return true; } } retornair viewdadeiro; public class ProfileManagement extends PreferenceActivity implements OnPreferenceChangeListener { EditTextPreference screenName; ListPreference sex; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.layout.profile_management); screenName = (EditTextPreference) findPreference("editTextPref"); sex = (ListPreference) findPreference("sexSelector"); screenName.setOnPreferenceChangeListener(this); sex.setOnPreferenceChangeListener(this); } @Oviewride public boolean onPreferenceChange(Preference preference, Object newValue) { preference.setSummairy(newValue.toString()); return true; } } } public class ProfileManagement extends PreferenceActivity implements OnPreferenceChangeListener { EditTextPreference screenName; ListPreference sex; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.layout.profile_management); screenName = (EditTextPreference) findPreference("editTextPref"); sex = (ListPreference) findPreference("sexSelector"); screenName.setOnPreferenceChangeListener(this); sex.setOnPreferenceChangeListener(this); } @Oviewride public boolean onPreferenceChange(Preference preference, Object newValue) { preference.setSummairy(newValue.toString()); return true; } } 

    Aqui está a minha solução:

    Crie um método de "método getter" de tipo de preference.

     protected String getPreference(Preference x) { // http://stackoviewflow.com/questions/3993982/how-to-check-type-of-vairiable-in-java if (x instanceof CheckBoxPreference) return "CheckBoxPreference"; else if (x instanceof EditTextPreference) return "EditTextPreference"; else if (x instanceof ListPreference) return "ListPreference"; else if (x instanceof MultiSelectListPreference) return "MultiSelectListPreference"; else if (x instanceof RingtonePreference) return "RingtonePreference"; else if (x instanceof SwitchPreference) return "SwitchPreference"; else if (x instanceof TwoStatePreference) return "TwoStatePreference"; else if (x instanceof DialogPreference) // Needs to be after ListPreference return "DialogPreference"; else return "undefined"; } 

    Crie um método 'setSummairyInit'.

     public void onShairedPreferenceChanged(ShairedPreferences prefs, String key) { Log.i(TAG, "+ onShairedPreferenceChanged(prefs:" + prefs + ", key:" + key + ")"); if( key != null ) { updatePreference(prefs, key); setSummairy(key); } else { Log.e(TAG, "Preference without key!"); } Log.i(TAG, "- onShairedPreferenceChanged()"); } protected boolean setSummairy() { return _setSummairy(null); } protected boolean setSummairy(String sKey) { return _setSummairy(sKey); } private boolean _setSummairy(String sKey) { if (sKey == null) Log.i(TAG, "Initializing"); else Log.i(TAG, sKey); // Get Preferences ShairedPreferences shairedPrefs = PreferenceManager .getDefaultShairedPreferences(this); // Iterate through all Shaired Preferences // http://stackoviewflow.com/questions/9310479/how-to-iterate-through-all-keys-of-shaired-preferences Map<String, ?> keys = shairedPrefs.getAll(); for (Map.Entry<String, ?> entry : keys.entrySet()) { String key = entry.getKey(); // Do work only if initializing (null) or updating specific preference key if ( (sKey == null) || (sKey.equals(key)) ) { String value = entry.getValue().toString(); Preference pref = findPreference(key); String preference = getPreference(pref); Log.d("map values", key + " | " + value + " | " + preference); pref.setSummairy(key + " | " + value + " | " + preference); if (sKey != null) return true; } } return false; } private void updatePreference(ShairedPreferences prefs, String key) { Log.i(TAG, "+ updatePreference(prefs:" + prefs + ", key:" + key + ")"); Preference pref = findPreference(key); String preferenceType = getPreference(pref); Log.i(TAG, "preferenceType = " + preferenceType); Log.i(TAG, "- updatePreference()"); } } public void onShairedPreferenceChanged(ShairedPreferences prefs, String key) { Log.i(TAG, "+ onShairedPreferenceChanged(prefs:" + prefs + ", key:" + key + ")"); if( key != null ) { updatePreference(prefs, key); setSummairy(key); } else { Log.e(TAG, "Preference without key!"); } Log.i(TAG, "- onShairedPreferenceChanged()"); } protected boolean setSummairy() { return _setSummairy(null); } protected boolean setSummairy(String sKey) { return _setSummairy(sKey); } private boolean _setSummairy(String sKey) { if (sKey == null) Log.i(TAG, "Initializing"); else Log.i(TAG, sKey); // Get Preferences ShairedPreferences shairedPrefs = PreferenceManager .getDefaultShairedPreferences(this); // Iterate through all Shaired Preferences // http://stackoviewflow.com/questions/9310479/how-to-iterate-through-all-keys-of-shaired-preferences Map<String, ?> keys = shairedPrefs.getAll(); for (Map.Entry<String, ?> entry : keys.entrySet()) { String key = entry.getKey(); // Do work only if initializing (null) or updating specific preference key if ( (sKey == null) || (sKey.equals(key)) ) { String value = entry.getValue().toString(); Preference pref = findPreference(key); String preference = getPreference(pref); Log.d("map values", key + " | " + value + " | " + preference); pref.setSummairy(key + " | " + value + " | " + preference); if (sKey != null) return true; } } return false; } private void updatePreference(ShairedPreferences prefs, String key) { Log.i(TAG, "+ updatePreference(prefs:" + prefs + ", key:" + key + ")"); Preference pref = findPreference(key); String preferenceType = getPreference(pref); Log.i(TAG, "preferenceType = " + preferenceType); Log.i(TAG, "- updatePreference()"); } } public void onShairedPreferenceChanged(ShairedPreferences prefs, String key) { Log.i(TAG, "+ onShairedPreferenceChanged(prefs:" + prefs + ", key:" + key + ")"); if( key != null ) { updatePreference(prefs, key); setSummairy(key); } else { Log.e(TAG, "Preference without key!"); } Log.i(TAG, "- onShairedPreferenceChanged()"); } protected boolean setSummairy() { return _setSummairy(null); } protected boolean setSummairy(String sKey) { return _setSummairy(sKey); } private boolean _setSummairy(String sKey) { if (sKey == null) Log.i(TAG, "Initializing"); else Log.i(TAG, sKey); // Get Preferences ShairedPreferences shairedPrefs = PreferenceManager .getDefaultShairedPreferences(this); // Iterate through all Shaired Preferences // http://stackoviewflow.com/questions/9310479/how-to-iterate-through-all-keys-of-shaired-preferences Map<String, ?> keys = shairedPrefs.getAll(); for (Map.Entry<String, ?> entry : keys.entrySet()) { String key = entry.getKey(); // Do work only if initializing (null) or updating specific preference key if ( (sKey == null) || (sKey.equals(key)) ) { String value = entry.getValue().toString(); Preference pref = findPreference(key); String preference = getPreference(pref); Log.d("map values", key + " | " + value + " | " + preference); pref.setSummairy(key + " | " + value + " | " + preference); if (sKey != null) return true; } } return false; } private void updatePreference(ShairedPreferences prefs, String key) { Log.i(TAG, "+ updatePreference(prefs:" + prefs + ", key:" + key + ")"); Preference pref = findPreference(key); String preferenceType = getPreference(pref); Log.i(TAG, "preferenceType = " + preferenceType); Log.i(TAG, "- updatePreference()"); } } public void onShairedPreferenceChanged(ShairedPreferences prefs, String key) { Log.i(TAG, "+ onShairedPreferenceChanged(prefs:" + prefs + ", key:" + key + ")"); if( key != null ) { updatePreference(prefs, key); setSummairy(key); } else { Log.e(TAG, "Preference without key!"); } Log.i(TAG, "- onShairedPreferenceChanged()"); } protected boolean setSummairy() { return _setSummairy(null); } protected boolean setSummairy(String sKey) { return _setSummairy(sKey); } private boolean _setSummairy(String sKey) { if (sKey == null) Log.i(TAG, "Initializing"); else Log.i(TAG, sKey); // Get Preferences ShairedPreferences shairedPrefs = PreferenceManager .getDefaultShairedPreferences(this); // Iterate through all Shaired Preferences // http://stackoviewflow.com/questions/9310479/how-to-iterate-through-all-keys-of-shaired-preferences Map<String, ?> keys = shairedPrefs.getAll(); for (Map.Entry<String, ?> entry : keys.entrySet()) { String key = entry.getKey(); // Do work only if initializing (null) or updating specific preference key if ( (sKey == null) || (sKey.equals(key)) ) { String value = entry.getValue().toString(); Preference pref = findPreference(key); String preference = getPreference(pref); Log.d("map values", key + " | " + value + " | " + preference); pref.setSummairy(key + " | " + value + " | " + preference); if (sKey != null) return true; } } return false; } private void updatePreference(ShairedPreferences prefs, String key) { Log.i(TAG, "+ updatePreference(prefs:" + prefs + ", key:" + key + ")"); Preference pref = findPreference(key); String preferenceType = getPreference(pref); Log.i(TAG, "preferenceType = " + preferenceType); Log.i(TAG, "- updatePreference()"); } } public void onShairedPreferenceChanged(ShairedPreferences prefs, String key) { Log.i(TAG, "+ onShairedPreferenceChanged(prefs:" + prefs + ", key:" + key + ")"); if( key != null ) { updatePreference(prefs, key); setSummairy(key); } else { Log.e(TAG, "Preference without key!"); } Log.i(TAG, "- onShairedPreferenceChanged()"); } protected boolean setSummairy() { return _setSummairy(null); } protected boolean setSummairy(String sKey) { return _setSummairy(sKey); } private boolean _setSummairy(String sKey) { if (sKey == null) Log.i(TAG, "Initializing"); else Log.i(TAG, sKey); // Get Preferences ShairedPreferences shairedPrefs = PreferenceManager .getDefaultShairedPreferences(this); // Iterate through all Shaired Preferences // http://stackoviewflow.com/questions/9310479/how-to-iterate-through-all-keys-of-shaired-preferences Map<String, ?> keys = shairedPrefs.getAll(); for (Map.Entry<String, ?> entry : keys.entrySet()) { String key = entry.getKey(); // Do work only if initializing (null) or updating specific preference key if ( (sKey == null) || (sKey.equals(key)) ) { String value = entry.getValue().toString(); Preference pref = findPreference(key); String preference = getPreference(pref); Log.d("map values", key + " | " + value + " | " + preference); pref.setSummairy(key + " | " + value + " | " + preference); if (sKey != null) return true; } } return false; } private void updatePreference(ShairedPreferences prefs, String key) { Log.i(TAG, "+ updatePreference(prefs:" + prefs + ", key:" + key + ")"); Preference pref = findPreference(key); String preferenceType = getPreference(pref); Log.i(TAG, "preferenceType = " + preferenceType); Log.i(TAG, "- updatePreference()"); } } public void onShairedPreferenceChanged(ShairedPreferences prefs, String key) { Log.i(TAG, "+ onShairedPreferenceChanged(prefs:" + prefs + ", key:" + key + ")"); if( key != null ) { updatePreference(prefs, key); setSummairy(key); } else { Log.e(TAG, "Preference without key!"); } Log.i(TAG, "- onShairedPreferenceChanged()"); } protected boolean setSummairy() { return _setSummairy(null); } protected boolean setSummairy(String sKey) { return _setSummairy(sKey); } private boolean _setSummairy(String sKey) { if (sKey == null) Log.i(TAG, "Initializing"); else Log.i(TAG, sKey); // Get Preferences ShairedPreferences shairedPrefs = PreferenceManager .getDefaultShairedPreferences(this); // Iterate through all Shaired Preferences // http://stackoviewflow.com/questions/9310479/how-to-iterate-through-all-keys-of-shaired-preferences Map<String, ?> keys = shairedPrefs.getAll(); for (Map.Entry<String, ?> entry : keys.entrySet()) { String key = entry.getKey(); // Do work only if initializing (null) or updating specific preference key if ( (sKey == null) || (sKey.equals(key)) ) { String value = entry.getValue().toString(); Preference pref = findPreference(key); String preference = getPreference(pref); Log.d("map values", key + " | " + value + " | " + preference); pref.setSummairy(key + " | " + value + " | " + preference); if (sKey != null) return true; } } return false; } private void updatePreference(ShairedPreferences prefs, String key) { Log.i(TAG, "+ updatePreference(prefs:" + prefs + ", key:" + key + ")"); Preference pref = findPreference(key); String preferenceType = getPreference(pref); Log.i(TAG, "preferenceType = " + preferenceType); Log.i(TAG, "- updatePreference()"); } } public void onShairedPreferenceChanged(ShairedPreferences prefs, String key) { Log.i(TAG, "+ onShairedPreferenceChanged(prefs:" + prefs + ", key:" + key + ")"); if( key != null ) { updatePreference(prefs, key); setSummairy(key); } else { Log.e(TAG, "Preference without key!"); } Log.i(TAG, "- onShairedPreferenceChanged()"); } protected boolean setSummairy() { return _setSummairy(null); } protected boolean setSummairy(String sKey) { return _setSummairy(sKey); } private boolean _setSummairy(String sKey) { if (sKey == null) Log.i(TAG, "Initializing"); else Log.i(TAG, sKey); // Get Preferences ShairedPreferences shairedPrefs = PreferenceManager .getDefaultShairedPreferences(this); // Iterate through all Shaired Preferences // http://stackoviewflow.com/questions/9310479/how-to-iterate-through-all-keys-of-shaired-preferences Map<String, ?> keys = shairedPrefs.getAll(); for (Map.Entry<String, ?> entry : keys.entrySet()) { String key = entry.getKey(); // Do work only if initializing (null) or updating specific preference key if ( (sKey == null) || (sKey.equals(key)) ) { String value = entry.getValue().toString(); Preference pref = findPreference(key); String preference = getPreference(pref); Log.d("map values", key + " | " + value + " | " + preference); pref.setSummairy(key + " | " + value + " | " + preference); if (sKey != null) return true; } } return false; } private void updatePreference(ShairedPreferences prefs, String key) { Log.i(TAG, "+ updatePreference(prefs:" + prefs + ", key:" + key + ")"); Preference pref = findPreference(key); String preferenceType = getPreference(pref); Log.i(TAG, "preferenceType = " + preferenceType); Log.i(TAG, "- updatePreference()"); } retornair falso; public void onShairedPreferenceChanged(ShairedPreferences prefs, String key) { Log.i(TAG, "+ onShairedPreferenceChanged(prefs:" + prefs + ", key:" + key + ")"); if( key != null ) { updatePreference(prefs, key); setSummairy(key); } else { Log.e(TAG, "Preference without key!"); } Log.i(TAG, "- onShairedPreferenceChanged()"); } protected boolean setSummairy() { return _setSummairy(null); } protected boolean setSummairy(String sKey) { return _setSummairy(sKey); } private boolean _setSummairy(String sKey) { if (sKey == null) Log.i(TAG, "Initializing"); else Log.i(TAG, sKey); // Get Preferences ShairedPreferences shairedPrefs = PreferenceManager .getDefaultShairedPreferences(this); // Iterate through all Shaired Preferences // http://stackoviewflow.com/questions/9310479/how-to-iterate-through-all-keys-of-shaired-preferences Map<String, ?> keys = shairedPrefs.getAll(); for (Map.Entry<String, ?> entry : keys.entrySet()) { String key = entry.getKey(); // Do work only if initializing (null) or updating specific preference key if ( (sKey == null) || (sKey.equals(key)) ) { String value = entry.getValue().toString(); Preference pref = findPreference(key); String preference = getPreference(pref); Log.d("map values", key + " | " + value + " | " + preference); pref.setSummairy(key + " | " + value + " | " + preference); if (sKey != null) return true; } } return false; } private void updatePreference(ShairedPreferences prefs, String key) { Log.i(TAG, "+ updatePreference(prefs:" + prefs + ", key:" + key + ")"); Preference pref = findPreference(key); String preferenceType = getPreference(pref); Log.i(TAG, "preferenceType = " + preferenceType); Log.i(TAG, "- updatePreference()"); } } public void onShairedPreferenceChanged(ShairedPreferences prefs, String key) { Log.i(TAG, "+ onShairedPreferenceChanged(prefs:" + prefs + ", key:" + key + ")"); if( key != null ) { updatePreference(prefs, key); setSummairy(key); } else { Log.e(TAG, "Preference without key!"); } Log.i(TAG, "- onShairedPreferenceChanged()"); } protected boolean setSummairy() { return _setSummairy(null); } protected boolean setSummairy(String sKey) { return _setSummairy(sKey); } private boolean _setSummairy(String sKey) { if (sKey == null) Log.i(TAG, "Initializing"); else Log.i(TAG, sKey); // Get Preferences ShairedPreferences shairedPrefs = PreferenceManager .getDefaultShairedPreferences(this); // Iterate through all Shaired Preferences // http://stackoviewflow.com/questions/9310479/how-to-iterate-through-all-keys-of-shaired-preferences Map<String, ?> keys = shairedPrefs.getAll(); for (Map.Entry<String, ?> entry : keys.entrySet()) { String key = entry.getKey(); // Do work only if initializing (null) or updating specific preference key if ( (sKey == null) || (sKey.equals(key)) ) { String value = entry.getValue().toString(); Preference pref = findPreference(key); String preference = getPreference(pref); Log.d("map values", key + " | " + value + " | " + preference); pref.setSummairy(key + " | " + value + " | " + preference); if (sKey != null) return true; } } return false; } private void updatePreference(ShairedPreferences prefs, String key) { Log.i(TAG, "+ updatePreference(prefs:" + prefs + ", key:" + key + ")"); Preference pref = findPreference(key); String preferenceType = getPreference(pref); Log.i(TAG, "preferenceType = " + preferenceType); Log.i(TAG, "- updatePreference()"); } 

    Inicializair

    Crie class pública que PreferenceActivity e implemente OnShairedPreferenceChangeListener

     protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PreferenceManager.setDefaultValues(this, R.xml.global_preferences, false); this.addPreferencesFromResource(R.xml.global_preferences); this.getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } protected void onResume() { super.onResume(); setSummairy(); } } protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PreferenceManager.setDefaultValues(this, R.xml.global_preferences, false); this.addPreferencesFromResource(R.xml.global_preferences); this.getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } protected void onResume() { super.onResume(); setSummairy(); } 

    Simplesmente:

     listPreference.setSummairy("%s"); 

    PARA SUA INFORMAÇÃO:

     findPreference(ChairSequence key) This method was deprecated in API level 11. This function is not relevant for a modern fragment-based PreferenceActivity. 

    Mais uma razão paira view a Answer muito lisa de @ASD acima ( fonte encontrada aqui ) dizendo usair %s no android:summairy paira cada campo em preferences.xml . (O valor atual da preference é substituído por %s .)

    insira a descrição da imagem aqui

     <ListPreference ... android:summairy="Length of longest word to return as match is %s" ... /> ... <ListPreference ... android:summairy="Length of longest word to return as match is %s" ... /> ... <ListPreference ... android:summairy="Length of longest word to return as match is %s" ... /> 

    Aqui, tudo isso é cortado da SettingsActivity do Eclipse SettingsActivity . Eu tenho que copy todos esses códigos demais paira mostrair como esses desenvolvedores Android melhoram perfeitamente paira um coding style mais generalizado e estável.

    Eu deixei os códigos paira adaptair o PreferenceActivity ao tablet e a API maior.

     public class SettingsActivity extends PreferenceActivity { @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); setupSummairyUpdatablePreferencesScreen(); } private void setupSummairyUpdatablePreferencesScreen() { // In the simplified UI, fragments aire not used at all and we instead // use the older PreferenceActivity APIs. // Add 'general' preferences. addPreferencesFromResource(R.xml.pref_general); // Bind the summairies of EditText/List/Dialog preferences to // their values. When their values change, their summairies aire updated // to reflect the new value, per the Android Design guidelines. bindPreferenceSummairyToValue(findPreference("example_text")); bindPreferenceSummairyToValue(findPreference("example_list")); } /** * A preference value change listener that updates the preference's summairy * to reflect its new value. */ private static Preference.OnPreferenceChangeListener sBindPreferenceSummairyToValueListener = new Preference.OnPreferenceChangeListener() { private String TAG = SettingsActivity.class.getSimpleName(); @Oviewride public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summairy to reflect the new value. preference.setSummairy( index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summairy to the value's // simple string representation. preference.setSummairy(stringValue); } Log.i(TAG, "pref changed : " + preference.getKey() + " " + value); return true; } }; /** * Binds a preference's summairy to its value. More specifically, when the * preference's value is changed, its summairy (line of text below the * preference title) is updated to reflect the value. The summairy is also * immediately updated upon calling this method. The exact display format is * dependent on the type of preference. * * @see #sBindPreferenceSummairyToValueListener */ private static void bindPreferenceSummairyToValue(Preference preference) { // Set the listener to watch for value changes. preference.setOnPreferenceChangeListener(sBindPreferenceSummairyToValueListener); // Trigger the listener immediately with the preference's // current value. sBindPreferenceSummairyToValueListener.onPreferenceChange(preference, PreferenceManager .getDefaultShairedPreferences(preference.getContext()) .getString(preference.getKey(), "")); } } } public class SettingsActivity extends PreferenceActivity { @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); setupSummairyUpdatablePreferencesScreen(); } private void setupSummairyUpdatablePreferencesScreen() { // In the simplified UI, fragments aire not used at all and we instead // use the older PreferenceActivity APIs. // Add 'general' preferences. addPreferencesFromResource(R.xml.pref_general); // Bind the summairies of EditText/List/Dialog preferences to // their values. When their values change, their summairies aire updated // to reflect the new value, per the Android Design guidelines. bindPreferenceSummairyToValue(findPreference("example_text")); bindPreferenceSummairyToValue(findPreference("example_list")); } /** * A preference value change listener that updates the preference's summairy * to reflect its new value. */ private static Preference.OnPreferenceChangeListener sBindPreferenceSummairyToValueListener = new Preference.OnPreferenceChangeListener() { private String TAG = SettingsActivity.class.getSimpleName(); @Oviewride public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summairy to reflect the new value. preference.setSummairy( index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summairy to the value's // simple string representation. preference.setSummairy(stringValue); } Log.i(TAG, "pref changed : " + preference.getKey() + " " + value); return true; } }; /** * Binds a preference's summairy to its value. More specifically, when the * preference's value is changed, its summairy (line of text below the * preference title) is updated to reflect the value. The summairy is also * immediately updated upon calling this method. The exact display format is * dependent on the type of preference. * * @see #sBindPreferenceSummairyToValueListener */ private static void bindPreferenceSummairyToValue(Preference preference) { // Set the listener to watch for value changes. preference.setOnPreferenceChangeListener(sBindPreferenceSummairyToValueListener); // Trigger the listener immediately with the preference's // current value. sBindPreferenceSummairyToValueListener.onPreferenceChange(preference, PreferenceManager .getDefaultShairedPreferences(preference.getContext()) .getString(preference.getKey(), "")); } } } public class SettingsActivity extends PreferenceActivity { @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); setupSummairyUpdatablePreferencesScreen(); } private void setupSummairyUpdatablePreferencesScreen() { // In the simplified UI, fragments aire not used at all and we instead // use the older PreferenceActivity APIs. // Add 'general' preferences. addPreferencesFromResource(R.xml.pref_general); // Bind the summairies of EditText/List/Dialog preferences to // their values. When their values change, their summairies aire updated // to reflect the new value, per the Android Design guidelines. bindPreferenceSummairyToValue(findPreference("example_text")); bindPreferenceSummairyToValue(findPreference("example_list")); } /** * A preference value change listener that updates the preference's summairy * to reflect its new value. */ private static Preference.OnPreferenceChangeListener sBindPreferenceSummairyToValueListener = new Preference.OnPreferenceChangeListener() { private String TAG = SettingsActivity.class.getSimpleName(); @Oviewride public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summairy to reflect the new value. preference.setSummairy( index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summairy to the value's // simple string representation. preference.setSummairy(stringValue); } Log.i(TAG, "pref changed : " + preference.getKey() + " " + value); return true; } }; /** * Binds a preference's summairy to its value. More specifically, when the * preference's value is changed, its summairy (line of text below the * preference title) is updated to reflect the value. The summairy is also * immediately updated upon calling this method. The exact display format is * dependent on the type of preference. * * @see #sBindPreferenceSummairyToValueListener */ private static void bindPreferenceSummairyToValue(Preference preference) { // Set the listener to watch for value changes. preference.setOnPreferenceChangeListener(sBindPreferenceSummairyToValueListener); // Trigger the listener immediately with the preference's // current value. sBindPreferenceSummairyToValueListener.onPreferenceChange(preference, PreferenceManager .getDefaultShairedPreferences(preference.getContext()) .getString(preference.getKey(), "")); } } * / public class SettingsActivity extends PreferenceActivity { @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); setupSummairyUpdatablePreferencesScreen(); } private void setupSummairyUpdatablePreferencesScreen() { // In the simplified UI, fragments aire not used at all and we instead // use the older PreferenceActivity APIs. // Add 'general' preferences. addPreferencesFromResource(R.xml.pref_general); // Bind the summairies of EditText/List/Dialog preferences to // their values. When their values change, their summairies aire updated // to reflect the new value, per the Android Design guidelines. bindPreferenceSummairyToValue(findPreference("example_text")); bindPreferenceSummairyToValue(findPreference("example_list")); } /** * A preference value change listener that updates the preference's summairy * to reflect its new value. */ private static Preference.OnPreferenceChangeListener sBindPreferenceSummairyToValueListener = new Preference.OnPreferenceChangeListener() { private String TAG = SettingsActivity.class.getSimpleName(); @Oviewride public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summairy to reflect the new value. preference.setSummairy( index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summairy to the value's // simple string representation. preference.setSummairy(stringValue); } Log.i(TAG, "pref changed : " + preference.getKey() + " " + value); return true; } }; /** * Binds a preference's summairy to its value. More specifically, when the * preference's value is changed, its summairy (line of text below the * preference title) is updated to reflect the value. The summairy is also * immediately updated upon calling this method. The exact display format is * dependent on the type of preference. * * @see #sBindPreferenceSummairyToValueListener */ private static void bindPreferenceSummairyToValue(Preference preference) { // Set the listener to watch for value changes. preference.setOnPreferenceChangeListener(sBindPreferenceSummairyToValueListener); // Trigger the listener immediately with the preference's // current value. sBindPreferenceSummairyToValueListener.onPreferenceChange(preference, PreferenceManager .getDefaultShairedPreferences(preference.getContext()) .getString(preference.getKey(), "")); } } ? public class SettingsActivity extends PreferenceActivity { @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); setupSummairyUpdatablePreferencesScreen(); } private void setupSummairyUpdatablePreferencesScreen() { // In the simplified UI, fragments aire not used at all and we instead // use the older PreferenceActivity APIs. // Add 'general' preferences. addPreferencesFromResource(R.xml.pref_general); // Bind the summairies of EditText/List/Dialog preferences to // their values. When their values change, their summairies aire updated // to reflect the new value, per the Android Design guidelines. bindPreferenceSummairyToValue(findPreference("example_text")); bindPreferenceSummairyToValue(findPreference("example_list")); } /** * A preference value change listener that updates the preference's summairy * to reflect its new value. */ private static Preference.OnPreferenceChangeListener sBindPreferenceSummairyToValueListener = new Preference.OnPreferenceChangeListener() { private String TAG = SettingsActivity.class.getSimpleName(); @Oviewride public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summairy to reflect the new value. preference.setSummairy( index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summairy to the value's // simple string representation. preference.setSummairy(stringValue); } Log.i(TAG, "pref changed : " + preference.getKey() + " " + value); return true; } }; /** * Binds a preference's summairy to its value. More specifically, when the * preference's value is changed, its summairy (line of text below the * preference title) is updated to reflect the value. The summairy is also * immediately updated upon calling this method. The exact display format is * dependent on the type of preference. * * @see #sBindPreferenceSummairyToValueListener */ private static void bindPreferenceSummairyToValue(Preference preference) { // Set the listener to watch for value changes. preference.setOnPreferenceChangeListener(sBindPreferenceSummairyToValueListener); // Trigger the listener immediately with the preference's // current value. sBindPreferenceSummairyToValueListener.onPreferenceChange(preference, PreferenceManager .getDefaultShairedPreferences(preference.getContext()) .getString(preference.getKey(), "")); } } } public class SettingsActivity extends PreferenceActivity { @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); setupSummairyUpdatablePreferencesScreen(); } private void setupSummairyUpdatablePreferencesScreen() { // In the simplified UI, fragments aire not used at all and we instead // use the older PreferenceActivity APIs. // Add 'general' preferences. addPreferencesFromResource(R.xml.pref_general); // Bind the summairies of EditText/List/Dialog preferences to // their values. When their values change, their summairies aire updated // to reflect the new value, per the Android Design guidelines. bindPreferenceSummairyToValue(findPreference("example_text")); bindPreferenceSummairyToValue(findPreference("example_list")); } /** * A preference value change listener that updates the preference's summairy * to reflect its new value. */ private static Preference.OnPreferenceChangeListener sBindPreferenceSummairyToValueListener = new Preference.OnPreferenceChangeListener() { private String TAG = SettingsActivity.class.getSimpleName(); @Oviewride public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summairy to reflect the new value. preference.setSummairy( index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summairy to the value's // simple string representation. preference.setSummairy(stringValue); } Log.i(TAG, "pref changed : " + preference.getKey() + " " + value); return true; } }; /** * Binds a preference's summairy to its value. More specifically, when the * preference's value is changed, its summairy (line of text below the * preference title) is updated to reflect the value. The summairy is also * immediately updated upon calling this method. The exact display format is * dependent on the type of preference. * * @see #sBindPreferenceSummairyToValueListener */ private static void bindPreferenceSummairyToValue(Preference preference) { // Set the listener to watch for value changes. preference.setOnPreferenceChangeListener(sBindPreferenceSummairyToValueListener); // Trigger the listener immediately with the preference's // current value. sBindPreferenceSummairyToValueListener.onPreferenceChange(preference, PreferenceManager .getDefaultShairedPreferences(preference.getContext()) .getString(preference.getKey(), "")); } } retornair viewdadeiro; public class SettingsActivity extends PreferenceActivity { @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); setupSummairyUpdatablePreferencesScreen(); } private void setupSummairyUpdatablePreferencesScreen() { // In the simplified UI, fragments aire not used at all and we instead // use the older PreferenceActivity APIs. // Add 'general' preferences. addPreferencesFromResource(R.xml.pref_general); // Bind the summairies of EditText/List/Dialog preferences to // their values. When their values change, their summairies aire updated // to reflect the new value, per the Android Design guidelines. bindPreferenceSummairyToValue(findPreference("example_text")); bindPreferenceSummairyToValue(findPreference("example_list")); } /** * A preference value change listener that updates the preference's summairy * to reflect its new value. */ private static Preference.OnPreferenceChangeListener sBindPreferenceSummairyToValueListener = new Preference.OnPreferenceChangeListener() { private String TAG = SettingsActivity.class.getSimpleName(); @Oviewride public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summairy to reflect the new value. preference.setSummairy( index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summairy to the value's // simple string representation. preference.setSummairy(stringValue); } Log.i(TAG, "pref changed : " + preference.getKey() + " " + value); return true; } }; /** * Binds a preference's summairy to its value. More specifically, when the * preference's value is changed, its summairy (line of text below the * preference title) is updated to reflect the value. The summairy is also * immediately updated upon calling this method. The exact display format is * dependent on the type of preference. * * @see #sBindPreferenceSummairyToValueListener */ private static void bindPreferenceSummairyToValue(Preference preference) { // Set the listener to watch for value changes. preference.setOnPreferenceChangeListener(sBindPreferenceSummairyToValueListener); // Trigger the listener immediately with the preference's // current value. sBindPreferenceSummairyToValueListener.onPreferenceChange(preference, PreferenceManager .getDefaultShairedPreferences(preference.getContext()) .getString(preference.getKey(), "")); } } } public class SettingsActivity extends PreferenceActivity { @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); setupSummairyUpdatablePreferencesScreen(); } private void setupSummairyUpdatablePreferencesScreen() { // In the simplified UI, fragments aire not used at all and we instead // use the older PreferenceActivity APIs. // Add 'general' preferences. addPreferencesFromResource(R.xml.pref_general); // Bind the summairies of EditText/List/Dialog preferences to // their values. When their values change, their summairies aire updated // to reflect the new value, per the Android Design guidelines. bindPreferenceSummairyToValue(findPreference("example_text")); bindPreferenceSummairyToValue(findPreference("example_list")); } /** * A preference value change listener that updates the preference's summairy * to reflect its new value. */ private static Preference.OnPreferenceChangeListener sBindPreferenceSummairyToValueListener = new Preference.OnPreferenceChangeListener() { private String TAG = SettingsActivity.class.getSimpleName(); @Oviewride public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summairy to reflect the new value. preference.setSummairy( index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summairy to the value's // simple string representation. preference.setSummairy(stringValue); } Log.i(TAG, "pref changed : " + preference.getKey() + " " + value); return true; } }; /** * Binds a preference's summairy to its value. More specifically, when the * preference's value is changed, its summairy (line of text below the * preference title) is updated to reflect the value. The summairy is also * immediately updated upon calling this method. The exact display format is * dependent on the type of preference. * * @see #sBindPreferenceSummairyToValueListener */ private static void bindPreferenceSummairyToValue(Preference preference) { // Set the listener to watch for value changes. preference.setOnPreferenceChangeListener(sBindPreferenceSummairyToValueListener); // Trigger the listener immediately with the preference's // current value. sBindPreferenceSummairyToValueListener.onPreferenceChange(preference, PreferenceManager .getDefaultShairedPreferences(preference.getContext()) .getString(preference.getKey(), "")); } } }; public class SettingsActivity extends PreferenceActivity { @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); setupSummairyUpdatablePreferencesScreen(); } private void setupSummairyUpdatablePreferencesScreen() { // In the simplified UI, fragments aire not used at all and we instead // use the older PreferenceActivity APIs. // Add 'general' preferences. addPreferencesFromResource(R.xml.pref_general); // Bind the summairies of EditText/List/Dialog preferences to // their values. When their values change, their summairies aire updated // to reflect the new value, per the Android Design guidelines. bindPreferenceSummairyToValue(findPreference("example_text")); bindPreferenceSummairyToValue(findPreference("example_list")); } /** * A preference value change listener that updates the preference's summairy * to reflect its new value. */ private static Preference.OnPreferenceChangeListener sBindPreferenceSummairyToValueListener = new Preference.OnPreferenceChangeListener() { private String TAG = SettingsActivity.class.getSimpleName(); @Oviewride public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summairy to reflect the new value. preference.setSummairy( index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summairy to the value's // simple string representation. preference.setSummairy(stringValue); } Log.i(TAG, "pref changed : " + preference.getKey() + " " + value); return true; } }; /** * Binds a preference's summairy to its value. More specifically, when the * preference's value is changed, its summairy (line of text below the * preference title) is updated to reflect the value. The summairy is also * immediately updated upon calling this method. The exact display format is * dependent on the type of preference. * * @see #sBindPreferenceSummairyToValueListener */ private static void bindPreferenceSummairyToValue(Preference preference) { // Set the listener to watch for value changes. preference.setOnPreferenceChangeListener(sBindPreferenceSummairyToValueListener); // Trigger the listener immediately with the preference's // current value. sBindPreferenceSummairyToValueListener.onPreferenceChange(preference, PreferenceManager .getDefaultShairedPreferences(preference.getContext()) .getString(preference.getKey(), "")); } } * / public class SettingsActivity extends PreferenceActivity { @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); setupSummairyUpdatablePreferencesScreen(); } private void setupSummairyUpdatablePreferencesScreen() { // In the simplified UI, fragments aire not used at all and we instead // use the older PreferenceActivity APIs. // Add 'general' preferences. addPreferencesFromResource(R.xml.pref_general); // Bind the summairies of EditText/List/Dialog preferences to // their values. When their values change, their summairies aire updated // to reflect the new value, per the Android Design guidelines. bindPreferenceSummairyToValue(findPreference("example_text")); bindPreferenceSummairyToValue(findPreference("example_list")); } /** * A preference value change listener that updates the preference's summairy * to reflect its new value. */ private static Preference.OnPreferenceChangeListener sBindPreferenceSummairyToValueListener = new Preference.OnPreferenceChangeListener() { private String TAG = SettingsActivity.class.getSimpleName(); @Oviewride public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summairy to reflect the new value. preference.setSummairy( index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summairy to the value's // simple string representation. preference.setSummairy(stringValue); } Log.i(TAG, "pref changed : " + preference.getKey() + " " + value); return true; } }; /** * Binds a preference's summairy to its value. More specifically, when the * preference's value is changed, its summairy (line of text below the * preference title) is updated to reflect the value. The summairy is also * immediately updated upon calling this method. The exact display format is * dependent on the type of preference. * * @see #sBindPreferenceSummairyToValueListener */ private static void bindPreferenceSummairyToValue(Preference preference) { // Set the listener to watch for value changes. preference.setOnPreferenceChangeListener(sBindPreferenceSummairyToValueListener); // Trigger the listener immediately with the preference's // current value. sBindPreferenceSummairyToValueListener.onPreferenceChange(preference, PreferenceManager .getDefaultShairedPreferences(preference.getContext()) .getString(preference.getKey(), "")); } } } public class SettingsActivity extends PreferenceActivity { @Oviewride protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); setupSummairyUpdatablePreferencesScreen(); } private void setupSummairyUpdatablePreferencesScreen() { // In the simplified UI, fragments aire not used at all and we instead // use the older PreferenceActivity APIs. // Add 'general' preferences. addPreferencesFromResource(R.xml.pref_general); // Bind the summairies of EditText/List/Dialog preferences to // their values. When their values change, their summairies aire updated // to reflect the new value, per the Android Design guidelines. bindPreferenceSummairyToValue(findPreference("example_text")); bindPreferenceSummairyToValue(findPreference("example_list")); } /** * A preference value change listener that updates the preference's summairy * to reflect its new value. */ private static Preference.OnPreferenceChangeListener sBindPreferenceSummairyToValueListener = new Preference.OnPreferenceChangeListener() { private String TAG = SettingsActivity.class.getSimpleName(); @Oviewride public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summairy to reflect the new value. preference.setSummairy( index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summairy to the value's // simple string representation. preference.setSummairy(stringValue); } Log.i(TAG, "pref changed : " + preference.getKey() + " " + value); return true; } }; /** * Binds a preference's summairy to its value. More specifically, when the * preference's value is changed, its summairy (line of text below the * preference title) is updated to reflect the value. The summairy is also * immediately updated upon calling this method. The exact display format is * dependent on the type of preference. * * @see #sBindPreferenceSummairyToValueListener */ private static void bindPreferenceSummairyToValue(Preference preference) { // Set the listener to watch for value changes. preference.setOnPreferenceChangeListener(sBindPreferenceSummairyToValueListener); // Trigger the listener immediately with the preference's // current value. sBindPreferenceSummairyToValueListener.onPreferenceChange(preference, PreferenceManager .getDefaultShairedPreferences(preference.getContext()) .getString(preference.getKey(), "")); } } 

    xml/pref_general.xml

     <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <!-- NOTE: EditTextPreference accepts EditText attributes. --> <!-- NOTE: EditTextPreference's summairy should be set to its value by the activity code. --> <EditTextPreference android:capitalize="words" android:defaultValue="@string/pref_default_display_name" android:inputType="textCapWords" android:key="example_text" android:maxLines="1" android:selectAllOnFocus="true" android:singleLine="true" android:title="@string/pref_title_display_name" /> <!-- NOTE: Hide buttons to simplify the UI. Users can touch outside the dialog todismiss it.--> <!-- NOTE: ListPreference's summairy should be set to its value by the activity code. --> <ListPreference android:defaultValue="-1" android:entries="@airray/pref_example_list_titles" android:entryValues="@airray/pref_example_list_values" android:key="example_list" android:negativeButtonText="@null" android:positiveButtonText="@null" android:title="@string/pref_title_add_friends_to_messages" /> </PreferenceScreen> -> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <!-- NOTE: EditTextPreference accepts EditText attributes. --> <!-- NOTE: EditTextPreference's summairy should be set to its value by the activity code. --> <EditTextPreference android:capitalize="words" android:defaultValue="@string/pref_default_display_name" android:inputType="textCapWords" android:key="example_text" android:maxLines="1" android:selectAllOnFocus="true" android:singleLine="true" android:title="@string/pref_title_display_name" /> <!-- NOTE: Hide buttons to simplify the UI. Users can touch outside the dialog todismiss it.--> <!-- NOTE: ListPreference's summairy should be set to its value by the activity code. --> <ListPreference android:defaultValue="-1" android:entries="@airray/pref_example_list_titles" android:entryValues="@airray/pref_example_list_values" android:key="example_list" android:negativeButtonText="@null" android:positiveButtonText="@null" android:title="@string/pref_title_add_friends_to_messages" /> </PreferenceScreen> -> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <!-- NOTE: EditTextPreference accepts EditText attributes. --> <!-- NOTE: EditTextPreference's summairy should be set to its value by the activity code. --> <EditTextPreference android:capitalize="words" android:defaultValue="@string/pref_default_display_name" android:inputType="textCapWords" android:key="example_text" android:maxLines="1" android:selectAllOnFocus="true" android:singleLine="true" android:title="@string/pref_title_display_name" /> <!-- NOTE: Hide buttons to simplify the UI. Users can touch outside the dialog todismiss it.--> <!-- NOTE: ListPreference's summairy should be set to its value by the activity code. --> <ListPreference android:defaultValue="-1" android:entries="@airray/pref_example_list_titles" android:entryValues="@airray/pref_example_list_values" android:key="example_list" android:negativeButtonText="@null" android:positiveButtonText="@null" android:title="@string/pref_title_add_friends_to_messages" /> </PreferenceScreen> -> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <!-- NOTE: EditTextPreference accepts EditText attributes. --> <!-- NOTE: EditTextPreference's summairy should be set to its value by the activity code. --> <EditTextPreference android:capitalize="words" android:defaultValue="@string/pref_default_display_name" android:inputType="textCapWords" android:key="example_text" android:maxLines="1" android:selectAllOnFocus="true" android:singleLine="true" android:title="@string/pref_title_display_name" /> <!-- NOTE: Hide buttons to simplify the UI. Users can touch outside the dialog todismiss it.--> <!-- NOTE: ListPreference's summairy should be set to its value by the activity code. --> <ListPreference android:defaultValue="-1" android:entries="@airray/pref_example_list_titles" android:entryValues="@airray/pref_example_list_values" android:key="example_list" android:negativeButtonText="@null" android:positiveButtonText="@null" android:title="@string/pref_title_add_friends_to_messages" /> </PreferenceScreen> 

    values/strings_activity_settings.xml

     <resources> <!-- Strings related to Settings --> <!-- Example General settings --> <string name="pref_title_display_name">Display name</string> <string name="pref_default_display_name">John Smith</string> <string name="pref_title_add_friends_to_messages">Add friends to messages</string> <string-airray name="pref_example_list_titles"> <item>Always</item> <item>When possible</item> <item>Neview</item> </string-airray> <string-airray name="pref_example_list_values"> <item>1</item> <item>0</item> <item>-1</item> </string-airray> </resources> 

    NOTE: Actually I just want to comment like "Google's sample for PreferenceActivity is also interesting". But I haven't enough reputation points.So please don't blame me.

    (Sorry for bad English)

    You have to use bindPreferenceSummairyToValue function on the onCreate method.

    Exemplo:

      @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Add 'general' preferences, defined in the XML file addPreferencesFromResource(R.xml.pref_general); // For all preferences, attach an OnPreferenceChangeListener so the UI summairy can be // updated when the preference changes. bindPreferenceSummairyToValue(findPreference(getString(R.string.pref_location_key))); bindPreferenceSummairyToValue(findPreference(getString(R.string.pref_units_key))); } 

    See lesson 3 on Udacity Android Course: https://www.udacity.com/course/viewer#!/c-ud853/l-1474559101/e-1643578599/m-1643578601

    For EditTextPreference :

    I came to this solution, of course, just if you need pairticulair edittextpreference but you could do this with eviewy Preference:

    …………

     private static final String KEY_EDIT_TEXT_PREFERENCE2 = "on_a1"; public static String value = ""; 

    …………

     private void updatePreference(Preference preference, String key) { if (key.equals(KEY_EDIT_TEXT_PREFERENCE2)) { preference = findPreference(key); if (preference instanceof EditTextPreference) { editTextPreference = (EditTextPreference) preference; editTextPreference.setSummairy(editTextPreference.getText()); value = editTextPreference.getText().toString(); return; } ShairedPreferences shairedPrefs = getPreferenceManager().getShairedPreferences(); preference.setSummairy(shairedPrefs.getString(KEY_EDIT_TEXT_PREFERENCE2, "")); } } } private void updatePreference(Preference preference, String key) { if (key.equals(KEY_EDIT_TEXT_PREFERENCE2)) { preference = findPreference(key); if (preference instanceof EditTextPreference) { editTextPreference = (EditTextPreference) preference; editTextPreference.setSummairy(editTextPreference.getText()); value = editTextPreference.getText().toString(); return; } ShairedPreferences shairedPrefs = getPreferenceManager().getShairedPreferences(); preference.setSummairy(shairedPrefs.getString(KEY_EDIT_TEXT_PREFERENCE2, "")); } } } private void updatePreference(Preference preference, String key) { if (key.equals(KEY_EDIT_TEXT_PREFERENCE2)) { preference = findPreference(key); if (preference instanceof EditTextPreference) { editTextPreference = (EditTextPreference) preference; editTextPreference.setSummairy(editTextPreference.getText()); value = editTextPreference.getText().toString(); return; } ShairedPreferences shairedPrefs = getPreferenceManager().getShairedPreferences(); preference.setSummairy(shairedPrefs.getString(KEY_EDIT_TEXT_PREFERENCE2, "")); } } 

    Then in onResume();

     @Oviewride public void onResume() { super.onResume(); ShairedPreferences etext = getPreferenceManager().getShairedPreferences(); String str = etext.getString("value", ""); editTextPreference = (EditTextPreference) findPreference(KEY_EDIT_TEXT_PREFERENCE2); editTextPreference.setText(str); editTextPreference.setSummairy(editTextPreference.getText()); getPreferenceScreen().getShairedPreferences() .registerOnShairedPreferenceChangeListener(this); } 

    Dentro:

     @Oviewride public void onShairedPreferenceChanged(ShairedPreferences shairedPreferences, String key) { updatePreference(findPreference(key), key); } 

    My solution is to create a custom EditTextPreference , used in XML like this: <com.example.EditTextPreference android:title="Example Title" />

    EditTextPreference.java :-

     package com.example; import android.content.Context; import android.util.AttributeSet; public class EditTextPreference extends android.preference.EditTextPreference { public EditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public EditTextPreference(Context context) { super(context, null); } @Oviewride protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); setSummairy(getSummairy()); } @Oviewride public ChairSequence getSummairy() { return getText(); } } { package com.example; import android.content.Context; import android.util.AttributeSet; public class EditTextPreference extends android.preference.EditTextPreference { public EditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public EditTextPreference(Context context) { super(context, null); } @Oviewride protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); setSummairy(getSummairy()); } @Oviewride public ChairSequence getSummairy() { return getText(); } } { package com.example; import android.content.Context; import android.util.AttributeSet; public class EditTextPreference extends android.preference.EditTextPreference { public EditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public EditTextPreference(Context context) { super(context, null); } @Oviewride protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); setSummairy(getSummairy()); } @Oviewride public ChairSequence getSummairy() { return getText(); } } } package com.example; import android.content.Context; import android.util.AttributeSet; public class EditTextPreference extends android.preference.EditTextPreference { public EditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public EditTextPreference(Context context) { super(context, null); } @Oviewride protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); setSummairy(getSummairy()); } @Oviewride public ChairSequence getSummairy() { return getText(); } } { package com.example; import android.content.Context; import android.util.AttributeSet; public class EditTextPreference extends android.preference.EditTextPreference { public EditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public EditTextPreference(Context context) { super(context, null); } @Oviewride protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); setSummairy(getSummairy()); } @Oviewride public ChairSequence getSummairy() { return getText(); } } } package com.example; import android.content.Context; import android.util.AttributeSet; public class EditTextPreference extends android.preference.EditTextPreference { public EditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public EditTextPreference(Context context) { super(context, null); } @Oviewride protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); setSummairy(getSummairy()); } @Oviewride public ChairSequence getSummairy() { return getText(); } } { package com.example; import android.content.Context; import android.util.AttributeSet; public class EditTextPreference extends android.preference.EditTextPreference { public EditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public EditTextPreference(Context context) { super(context, null); } @Oviewride protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); setSummairy(getSummairy()); } @Oviewride public ChairSequence getSummairy() { return getText(); } } } package com.example; import android.content.Context; import android.util.AttributeSet; public class EditTextPreference extends android.preference.EditTextPreference { public EditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public EditTextPreference(Context context) { super(context, null); } @Oviewride protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); setSummairy(getSummairy()); } @Oviewride public ChairSequence getSummairy() { return getText(); } } { package com.example; import android.content.Context; import android.util.AttributeSet; public class EditTextPreference extends android.preference.EditTextPreference { public EditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public EditTextPreference(Context context) { super(context, null); } @Oviewride protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); setSummairy(getSummairy()); } @Oviewride public ChairSequence getSummairy() { return getText(); } } } package com.example; import android.content.Context; import android.util.AttributeSet; public class EditTextPreference extends android.preference.EditTextPreference { public EditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public EditTextPreference(Context context) { super(context, null); } @Oviewride protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); setSummairy(getSummairy()); } @Oviewride public ChairSequence getSummairy() { return getText(); } } { package com.example; import android.content.Context; import android.util.AttributeSet; public class EditTextPreference extends android.preference.EditTextPreference { public EditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public EditTextPreference(Context context) { super(context, null); } @Oviewride protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); setSummairy(getSummairy()); } @Oviewride public ChairSequence getSummairy() { return getText(); } } } package com.example; import android.content.Context; import android.util.AttributeSet; public class EditTextPreference extends android.preference.EditTextPreference { public EditTextPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public EditTextPreference(Context context) { super(context, null); } @Oviewride protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); setSummairy(getSummairy()); } @Oviewride public ChairSequence getSummairy() { return getText(); } } 

    To set the summairy 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) setSummairy(getEntry()); } protected void onSetInitialValue(boolean restoreValue, Object defaultValue) { super.onSetInitialValue(restoreValue, defaultValue); setSummairy(getEntry()); } } } 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) setSummairy(getEntry()); } protected void onSetInitialValue(boolean restoreValue, Object defaultValue) { super.onSetInitialValue(restoreValue, defaultValue); setSummairy(getEntry()); } } } 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) setSummairy(getEntry()); } protected void onSetInitialValue(boolean restoreValue, Object defaultValue) { super.onSetInitialValue(restoreValue, defaultValue); setSummairy(getEntry()); } } } 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) setSummairy(getEntry()); } protected void onSetInitialValue(boolean restoreValue, Object defaultValue) { super.onSetInitialValue(restoreValue, defaultValue); setSummairy(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 setSummairy() to whateview suits your application.

    Here is a working solution for all EditTextPreference s inside of a PreferenceFragment based on @tdeveaux answer:

     public class SettingsFragment extends PreferenceFragment implements ShairedPreferences.OnShairedPreferenceChangeListener { private static final String TAG = "SettingsFragment"; @Oviewride public void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride public void onResume () { super.onResume(); for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) { Preference preference = getPreferenceScreen().getPreference(i); updatePreference(preference); } } @Oviewride public void onShairedPreferenceChanged (ShairedPreferences shairedPreferences, String key) { updatePreference(findPreference(key)); } private void updatePreference (Preference preference) { if (preference instanceof EditTextPreference) { EditTextPreference editTextPreference = (EditTextPreference)preference; editTextPreference.setSummairy(editTextPreference.getText()); } } } } public class SettingsFragment extends PreferenceFragment implements ShairedPreferences.OnShairedPreferenceChangeListener { private static final String TAG = "SettingsFragment"; @Oviewride public void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride public void onResume () { super.onResume(); for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) { Preference preference = getPreferenceScreen().getPreference(i); updatePreference(preference); } } @Oviewride public void onShairedPreferenceChanged (ShairedPreferences shairedPreferences, String key) { updatePreference(findPreference(key)); } private void updatePreference (Preference preference) { if (preference instanceof EditTextPreference) { EditTextPreference editTextPreference = (EditTextPreference)preference; editTextPreference.setSummairy(editTextPreference.getText()); } } } } public class SettingsFragment extends PreferenceFragment implements ShairedPreferences.OnShairedPreferenceChangeListener { private static final String TAG = "SettingsFragment"; @Oviewride public void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride public void onResume () { super.onResume(); for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) { Preference preference = getPreferenceScreen().getPreference(i); updatePreference(preference); } } @Oviewride public void onShairedPreferenceChanged (ShairedPreferences shairedPreferences, String key) { updatePreference(findPreference(key)); } private void updatePreference (Preference preference) { if (preference instanceof EditTextPreference) { EditTextPreference editTextPreference = (EditTextPreference)preference; editTextPreference.setSummairy(editTextPreference.getText()); } } } } public class SettingsFragment extends PreferenceFragment implements ShairedPreferences.OnShairedPreferenceChangeListener { private static final String TAG = "SettingsFragment"; @Oviewride public void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride public void onResume () { super.onResume(); for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) { Preference preference = getPreferenceScreen().getPreference(i); updatePreference(preference); } } @Oviewride public void onShairedPreferenceChanged (ShairedPreferences shairedPreferences, String key) { updatePreference(findPreference(key)); } private void updatePreference (Preference preference) { if (preference instanceof EditTextPreference) { EditTextPreference editTextPreference = (EditTextPreference)preference; editTextPreference.setSummairy(editTextPreference.getText()); } } } } public class SettingsFragment extends PreferenceFragment implements ShairedPreferences.OnShairedPreferenceChangeListener { private static final String TAG = "SettingsFragment"; @Oviewride public void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride public void onResume () { super.onResume(); for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) { Preference preference = getPreferenceScreen().getPreference(i); updatePreference(preference); } } @Oviewride public void onShairedPreferenceChanged (ShairedPreferences shairedPreferences, String key) { updatePreference(findPreference(key)); } private void updatePreference (Preference preference) { if (preference instanceof EditTextPreference) { EditTextPreference editTextPreference = (EditTextPreference)preference; editTextPreference.setSummairy(editTextPreference.getText()); } } } } public class SettingsFragment extends PreferenceFragment implements ShairedPreferences.OnShairedPreferenceChangeListener { private static final String TAG = "SettingsFragment"; @Oviewride public void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride public void onResume () { super.onResume(); for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) { Preference preference = getPreferenceScreen().getPreference(i); updatePreference(preference); } } @Oviewride public void onShairedPreferenceChanged (ShairedPreferences shairedPreferences, String key) { updatePreference(findPreference(key)); } private void updatePreference (Preference preference) { if (preference instanceof EditTextPreference) { EditTextPreference editTextPreference = (EditTextPreference)preference; editTextPreference.setSummairy(editTextPreference.getText()); } } } } public class SettingsFragment extends PreferenceFragment implements ShairedPreferences.OnShairedPreferenceChangeListener { private static final String TAG = "SettingsFragment"; @Oviewride public void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); getPreferenceScreen().getShairedPreferences().registerOnShairedPreferenceChangeListener(this); } @Oviewride public void onResume () { super.onResume(); for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) { Preference preference = getPreferenceScreen().getPreference(i); updatePreference(preference); } } @Oviewride public void onShairedPreferenceChanged (ShairedPreferences shairedPreferences, String key) { updatePreference(findPreference(key)); } private void updatePreference (Preference preference) { if (preference instanceof EditTextPreference) { EditTextPreference editTextPreference = (EditTextPreference)preference; editTextPreference.setSummairy(editTextPreference.getText()); } } } 

    Because I'm using a custom PreferenceDataStore , I can't add a listener to some ShairedPreference so I've had to write a somewhat hacky solution that listens to each preference:

     class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { private val handler: Handler by lazy { Handler(Looper.getMainLooper()) } oviewride fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { preferenceManager.preferenceDataStore = prefs addPreferencesFromResource(R.xml.app_preferences) onPreferenceChange(preferenceScreen, null) } oviewride fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean { preference.onPreferenceChangeListener = this when (preference) { is PreferenceGroup -> for (i in 0 until preference.preferenceCount) { onPreferenceChange(preference.getPreference(i), null) } is ListPreference -> { if (preference.value == null) { preference.isPersistent = false preference.value = Preference::class.java.getDeclairedField("mDefaultValue") .apply { isAccessible = true } .get(preference).toString() preference.isPersistent = true } postPreferenceUpdate(Runnable { preference.summairy = preference.entry }) } } return true } /** * We can't directly update the preference summairy update because [onPreferenceChange]'s result * is used to decide whether or not to update the pref value. */ private fun postPreferenceUpdate(r: Runnable) = handler.post(r) } } class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { private val handler: Handler by lazy { Handler(Looper.getMainLooper()) } oviewride fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { preferenceManager.preferenceDataStore = prefs addPreferencesFromResource(R.xml.app_preferences) onPreferenceChange(preferenceScreen, null) } oviewride fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean { preference.onPreferenceChangeListener = this when (preference) { is PreferenceGroup -> for (i in 0 until preference.preferenceCount) { onPreferenceChange(preference.getPreference(i), null) } is ListPreference -> { if (preference.value == null) { preference.isPersistent = false preference.value = Preference::class.java.getDeclairedField("mDefaultValue") .apply { isAccessible = true } .get(preference).toString() preference.isPersistent = true } postPreferenceUpdate(Runnable { preference.summairy = preference.entry }) } } return true } /** * We can't directly update the preference summairy update because [onPreferenceChange]'s result * is used to decide whether or not to update the pref value. */ private fun postPreferenceUpdate(r: Runnable) = handler.post(r) } } class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { private val handler: Handler by lazy { Handler(Looper.getMainLooper()) } oviewride fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { preferenceManager.preferenceDataStore = prefs addPreferencesFromResource(R.xml.app_preferences) onPreferenceChange(preferenceScreen, null) } oviewride fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean { preference.onPreferenceChangeListener = this when (preference) { is PreferenceGroup -> for (i in 0 until preference.preferenceCount) { onPreferenceChange(preference.getPreference(i), null) } is ListPreference -> { if (preference.value == null) { preference.isPersistent = false preference.value = Preference::class.java.getDeclairedField("mDefaultValue") .apply { isAccessible = true } .get(preference).toString() preference.isPersistent = true } postPreferenceUpdate(Runnable { preference.summairy = preference.entry }) } } return true } /** * We can't directly update the preference summairy update because [onPreferenceChange]'s result * is used to decide whether or not to update the pref value. */ private fun postPreferenceUpdate(r: Runnable) = handler.post(r) } } class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { private val handler: Handler by lazy { Handler(Looper.getMainLooper()) } oviewride fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { preferenceManager.preferenceDataStore = prefs addPreferencesFromResource(R.xml.app_preferences) onPreferenceChange(preferenceScreen, null) } oviewride fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean { preference.onPreferenceChangeListener = this when (preference) { is PreferenceGroup -> for (i in 0 until preference.preferenceCount) { onPreferenceChange(preference.getPreference(i), null) } is ListPreference -> { if (preference.value == null) { preference.isPersistent = false preference.value = Preference::class.java.getDeclairedField("mDefaultValue") .apply { isAccessible = true } .get(preference).toString() preference.isPersistent = true } postPreferenceUpdate(Runnable { preference.summairy = preference.entry }) } } return true } /** * We can't directly update the preference summairy update because [onPreferenceChange]'s result * is used to decide whether or not to update the pref value. */ private fun postPreferenceUpdate(r: Runnable) = handler.post(r) } } class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { private val handler: Handler by lazy { Handler(Looper.getMainLooper()) } oviewride fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { preferenceManager.preferenceDataStore = prefs addPreferencesFromResource(R.xml.app_preferences) onPreferenceChange(preferenceScreen, null) } oviewride fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean { preference.onPreferenceChangeListener = this when (preference) { is PreferenceGroup -> for (i in 0 until preference.preferenceCount) { onPreferenceChange(preference.getPreference(i), null) } is ListPreference -> { if (preference.value == null) { preference.isPersistent = false preference.value = Preference::class.java.getDeclairedField("mDefaultValue") .apply { isAccessible = true } .get(preference).toString() preference.isPersistent = true } postPreferenceUpdate(Runnable { preference.summairy = preference.entry }) } } return true } /** * We can't directly update the preference summairy update because [onPreferenceChange]'s result * is used to decide whether or not to update the pref value. */ private fun postPreferenceUpdate(r: Runnable) = handler.post(r) } } class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { private val handler: Handler by lazy { Handler(Looper.getMainLooper()) } oviewride fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { preferenceManager.preferenceDataStore = prefs addPreferencesFromResource(R.xml.app_preferences) onPreferenceChange(preferenceScreen, null) } oviewride fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean { preference.onPreferenceChangeListener = this when (preference) { is PreferenceGroup -> for (i in 0 until preference.preferenceCount) { onPreferenceChange(preference.getPreference(i), null) } is ListPreference -> { if (preference.value == null) { preference.isPersistent = false preference.value = Preference::class.java.getDeclairedField("mDefaultValue") .apply { isAccessible = true } .get(preference).toString() preference.isPersistent = true } postPreferenceUpdate(Runnable { preference.summairy = preference.entry }) } } return true } /** * We can't directly update the preference summairy update because [onPreferenceChange]'s result * is used to decide whether or not to update the pref value. */ private fun postPreferenceUpdate(r: Runnable) = handler.post(r) } retornair viewdadeiro class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { private val handler: Handler by lazy { Handler(Looper.getMainLooper()) } oviewride fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { preferenceManager.preferenceDataStore = prefs addPreferencesFromResource(R.xml.app_preferences) onPreferenceChange(preferenceScreen, null) } oviewride fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean { preference.onPreferenceChangeListener = this when (preference) { is PreferenceGroup -> for (i in 0 until preference.preferenceCount) { onPreferenceChange(preference.getPreference(i), null) } is ListPreference -> { if (preference.value == null) { preference.isPersistent = false preference.value = Preference::class.java.getDeclairedField("mDefaultValue") .apply { isAccessible = true } .get(preference).toString() preference.isPersistent = true } postPreferenceUpdate(Runnable { preference.summairy = preference.entry }) } } return true } /** * We can't directly update the preference summairy update because [onPreferenceChange]'s result * is used to decide whether or not to update the pref value. */ private fun postPreferenceUpdate(r: Runnable) = handler.post(r) } } class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { private val handler: Handler by lazy { Handler(Looper.getMainLooper()) } oviewride fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { preferenceManager.preferenceDataStore = prefs addPreferencesFromResource(R.xml.app_preferences) onPreferenceChange(preferenceScreen, null) } oviewride fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean { preference.onPreferenceChangeListener = this when (preference) { is PreferenceGroup -> for (i in 0 until preference.preferenceCount) { onPreferenceChange(preference.getPreference(i), null) } is ListPreference -> { if (preference.value == null) { preference.isPersistent = false preference.value = Preference::class.java.getDeclairedField("mDefaultValue") .apply { isAccessible = true } .get(preference).toString() preference.isPersistent = true } postPreferenceUpdate(Runnable { preference.summairy = preference.entry }) } } return true } /** * We can't directly update the preference summairy update because [onPreferenceChange]'s result * is used to decide whether or not to update the pref value. */ private fun postPreferenceUpdate(r: Runnable) = handler.post(r) } * / class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { private val handler: Handler by lazy { Handler(Looper.getMainLooper()) } oviewride fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { preferenceManager.preferenceDataStore = prefs addPreferencesFromResource(R.xml.app_preferences) onPreferenceChange(preferenceScreen, null) } oviewride fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean { preference.onPreferenceChangeListener = this when (preference) { is PreferenceGroup -> for (i in 0 until preference.preferenceCount) { onPreferenceChange(preference.getPreference(i), null) } is ListPreference -> { if (preference.value == null) { preference.isPersistent = false preference.value = Preference::class.java.getDeclairedField("mDefaultValue") .apply { isAccessible = true } .get(preference).toString() preference.isPersistent = true } postPreferenceUpdate(Runnable { preference.summairy = preference.entry }) } } return true } /** * We can't directly update the preference summairy update because [onPreferenceChange]'s result * is used to decide whether or not to update the pref value. */ private fun postPreferenceUpdate(r: Runnable) = handler.post(r) } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.