开发者

Android: onSharedPreferenceChanged()

开发者 https://www.devze.com 2023-02-23 06:22 出处:网络
I have a listPreference in Settings in my App. And i have a onSharedPreferenceChanged() method where i开发者_JAVA百科 do something if the value was changed. But if user click on the same list item onS

I have a listPreference in Settings in my App. And i have a onSharedPreferenceChanged() method where i开发者_JAVA百科 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


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


Just use sharedPreferences.getString(key,defValue);

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号