Reputation: 1251
If I disable using setEnabled(false)
the switch is (1) set to off and (2) I don't get a response from the OnClickListener
to launch a dialog.
Edit: In this case, I don't want the switch to automatically switch from on to off.
Has anyone dealt with this problem?
Upvotes: 3
Views: 2292
Reputation: 1251
The solution was to use setChecked(true)
inside the OnPreferenceClickListener
callback then launch the dialog.
Note: this did not work inside of the OnPreferenceChangeListener
callback.
Upvotes: 6
Reputation: 857
For those who want the code :
if (!BuildConfig.FULL_VERSION) {
SwitchPreferenceCompat preference = (SwitchPreferenceCompat) findPreference(getString(R.string.pref_notifications_service_key));
preference.setDefaultValue(false);
preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
((SwitchPreferenceCompat) preference).setChecked(false);
new ProFeatureDialogFragment().show(getFragmentManager(), "PRO_FEATURE_TAG");
return false;
}
});
}
Upvotes: 2