Search code examples
androidandroid-activitysettingsandroid-preferences

Android - How to change texts in the preferences activity dynamically?


Hello fellow programmers, I have a little problem with Preferences activity.

http://developer.android.com/reference/android/preference/PreferenceActivity.html

I've got just one preference category and a listPreference:

<?xml version="1.0" encoding="utf-8"?>

<PreferenceCategory android:title="@string/basic_settings" >
    <ListPreference
        android:defaultValue="70"
        android:entries="@array/listArray"
        android:entryValues="@array/listValues"
        android:key="updates_interval"
        android:persistent="true"
        android:summary="@string/SOME_SUMMARY"
        android:title="@string/SOME_TITLE" />
</PreferenceCategory>

I need to have the selected value (the default one or the user defined one) written in the summary of the listPreference, for example: We will have at least 70 characters.

How can I do this from the code?

Any help is appreciated


Solution

  • Try like this..

     Preference customPref = (Preference) findPreference("updates_interval");<-- your preferences key
     customPref.setSummary("desired string");