Vishwa Madushan Vishwa Madushan -4 years ago 158
Java Question

Update Textview right after user change settings value

In my app I let the user choose a name to display. It should display as:


I can successfully update settings. I used PreferenceActivity.
I can change the value too. But to change the text in the selected textview, I have to restart the app.

How can I update my textview right after users update the value in settings?

Answer Source
Preference.OnPreferenceChangeListener changeListener = new Preference.OnPreferenceChangeListener() {
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        // Code goes here            
        return true;

EditTextPreference pref = (EditTextPreference)findPreference(getString(R.string.pref1));

EditTextPreference pref2 = (EditTextPreference)findPreference(getString(R.string.pref2));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download