I've got a ListPreference in which I can select items and set parameters for purposes. When I click on it in my Settings Fragment where all of my Preferences are, it opens a dialog and lets me choose the items listed in it. I am using two handlers, OnPreferenceClickListener (Called when I click on my ListPreference) and OnPreferenceChangeListener (Called when I select an item in it).
I want to block the dialog from opening without disabling the ListPreference at all so that I cannot select the items in it. I've blocked changing the items with a global boolean in my OnPreferenceChangeListener.
boolean canChange = true;
final ListPreference listPreference = (ListPreference) findPreference("myListPreference");
listPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
canChange = myCondition;
return true;
}
});
listPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if(canChange)
someValueHolder = listPreference.findIndexOfValue(newValue.toString());
return true;
}
});
This is a bad code but the best attempt I could think of to avoid changing the listed items if myCondition is false. But I want to know how I can block the Dialog from popping up when I click on the preference if myCondition is false and instead open up a dialog with a warning message like You cannot change this ListPreference when myCondition is false!?