I have a preferences Activity with a ListPreference on it and I use this preferences in another activity, But I want to show a Toast whenever, user changing option in preference Activity. For example, when user clicks on second radio button in ListPreference, suddenly a toast shown and says "second".
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
What is the problem?
Resolve the preference and set a listener that does the toast? Something like this for example
ListPreference listPreference = findPreference(key);
listPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Toast.makeText(SettingsActivity.this, "second", Toast.LENGTH_LONG).show();
return true;
}
});