Jim
Jim

Reputation: 9234

Android: onSharedPreferenceChanged()

I have a listPreference in Settings in my App. And i have a onSharedPreferenceChanged() method where i do something if the value was changed. But if user click on the same list item onSharedPreferenceChanged() called again. But i dont want to do anything if user clicked on the same row in listPreference... How to handle that ? How to check in onSharedPreferenceChanged() if the value was change or not ? Thanks.

For example

 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
        String key) {
    if (key.equals(SOME_KEY)) {
        setResult(2);
    }
}

But I dont wont to set result if the value is the same

Upvotes: 0

Views: 3605

Answers (2)

Dr.jacky
Dr.jacky

Reputation: 3547

Just use sharedPreferences.getString(key,defValue);

Upvotes: 0

Michael
Michael

Reputation: 54705

You'd better do that in Preference.OnPreferenceChangeListener subclass.

Upvotes: 1

Related Questions