Show a Toast when user change setting in preferences activity

*爱你&永不变心* 提交于 2019-12-11 08:17:13

问题


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;
        }
    });


来源:https://stackoverflow.com/questions/13665409/show-a-toast-when-user-change-setting-in-preferences-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!