Show a Toast when user change setting in preferences activity
Asked Answered
B

1

1

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".

Blotto answered 2/12, 2012 at 1:0 Comment(1)
@mango I have just created a pref activity to make it show preferences, but i don't know where i should define a code to show a toast, in pref activity maybe?Blotto
P
2

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;
        }
    });
Parody answered 2/12, 2012 at 1:9 Comment(2)
Yes, I want something exactly like this! I understand other lines than first line. what is (key)? how should I fill that?Blotto
@Blotto Sometimes the man pages can be your friend, take a read of this link and then look at your preferences.xml file, the light bulb moment will come shortly thereafter.Aubry

© 2022 - 2024 — McMap. All rights reserved.