java – SwitchPreference setOnPreferenceChangeListener not call-ThrowExceptions

Exception or error:

I tried to showing the Toast, but it’s not called when I changed SwitchPreference state.(JAVA)

    SwitchPreference adwareMalware = findPreference("adwareMalware");
    adwareMalware.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        public boolean onPreferenceChange(Preference preference, Object o) {
            if (adwareMalware.isChecked()) {
                Toast.makeText(getContext(), "Unchecked", Toast.LENGTH_SHORT).show();

                // Checked the switch programmatically
            } else {
                Toast.makeText(getContext(), "Checked", Toast.LENGTH_SHORT).show();

                url = malware;
                // Unchecked the switch programmatically
            return true;
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *