Reviewing your code, you are using the class Preference and by means of onPreferenceClick()
, you can not get a status you just get the preference and its value.
onPreferenceClick () Called when you clicked on a
preference.
Instead, if you would use SwitchPreference through onPreferenceChange () you can determine when a preference change is made.
SwitchPreference estado = (SwitchPreference) findPreference("estado");
estado.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if(!((Boolean) newValue)) {
Log.i("Preferencias", "NO ACTIVADO.");
} else {
Log.i("Preferencias", "ACTIVADO.");
}
return true;
}
});
This is an example of how the SwitchPreference
would be declared within the layout:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="Mis Preferencias" >
<SwitchPreference
android:key="estado"
android:title="verifica el valor del estado" />
</PreferenceCategory>
</PreferenceScreen>
When making a change in the Switch you could detect the change within onPreferenceChange()
, in the case of the example that I will indicate if it is activated or deactivated the Switch
.