I wanna display a dialog when the user selects a specific item from a ListPreference in my preferenceActivity. But, I cannot get the onSharedPreferenceChanged() to work. I've put a Toast in the beginning of the method, and it does not show, so the method doesn't even run through, why is this?
Here's my code: (Thanks)
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
Toast.makeText(Preferences.this, "prefs Changed", Toast.LENGTH_SHORT)
.show();
if (key.equals("boolean_ad_type")) {
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
String value = sharedPreferences.getString("boolean_ad_type", "");
if (value != null && value.equals("Pop-up Ads")) {
Toast.makeText(Preferences.this, "Pop-up Ads Selected",
Toast.LENGTH_SHORT).show();
}
}
}
And do I need to implement it in the activity like this? (I've tried with and without, no difference)
public class Preferences extends PreferenceActivity
implements OnSharedPreferenceChangeListener {