SagiLow
SagiLow

Reputation: 6049

preference value doesn't change when overridden with 'OnPreferenceChangeListener' - Android

I've implemented a OnPreferenceChangeListener on two preference object in my preference page ( extends PreferenceActivity)
But ever since the preference value isn't updated upon change,
I even tried using :

SharedPreferences sharedPreferences = getSharedPreferences("myCustomSharedPrefs",
        Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(preference.getKey(), Integer.parseInt(newValue.toString()));
editor.commit();

Where preference is the changed preference and newValue is the new value...
What am I missing ?

Thanks

Upvotes: 0

Views: 428

Answers (2)

Joseph Selvaraj
Joseph Selvaraj

Reputation: 2237

Can you see if preference.getKey() is giving the correct name? Can you print in your console and see. Code looks clean to me. May be the name is different than what is expected.

Also make sure that the value is also having the correct value.

Upvotes: 0

Stochastically
Stochastically

Reputation: 7846

You need to return true to get the value updated, see the Android documentation.

Upvotes: 1

Related Questions