AndroidDeveloperLB / MaterialPreferenceLibrary

Allows to have an ActionBar on PreferenceActivity
Apache License 2.0
406 stars 69 forks source link

SwitchPreference error #17

Closed jemshit closed 9 years ago

jemshit commented 9 years ago

I'm getting wrong value when Clicked on switchpreference, when i switch on , it returns "false", when i switch off it returns "true". But if i check its values before clicking, it returns right value

<com.lb.material_preferences_library.custom_preferences.SwitchPreference
            android:defaultValue="false"
            android:key="switchPreference"  
            android:title="@string/"
            app:summaryOff="@string/"
            app:summaryOn="@string/" />

SwitchPreference notificationPreference=(SwitchPreference)findPreference("switchPreference");
        notificationPreference.setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                ...
                return true;
            }
        });
AndroidDeveloperLB commented 9 years ago

This is not related to the library. That's how it works on the original framework. Please read the documentation: http://developer.android.com/reference/android/preference/Preference.html#setOnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) http://developer.android.com/reference/android/preference/Preference.OnPreferenceChangeListener.html

When are inside the "...", the value is still the previous one, as you can decide if you allow to really change the value (which is what the "return true" does - confirm the change). If you wish to check the new value, just check it out (it's even called "newValue").

jemshit commented 9 years ago

Thanks :+1: