Which method fires when changing a value in the PreferenceActivity class?

1

I would like to capture the user-modified field in a class that inherits from PreferenceActivity.

I tried unsuccessfully to override: onContentChanged () and onActivityResult.

    
asked by anonymous 02.09.2014 / 15:06

1 answer

2

The Preference class, as well as various Android elements, have events.

In the case of class Preference , it has two winds: OnPreferenceChange and OnPreferenceClick . I think the first one is what you need.

To be notified of the change of value of a Preference , you must register a OnPreferenceChangeListener in the desired preference.

To use:

Preference p = findPreference("erp_cod_vendedor");

p.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         // Valor mudou, faca algo
         return true; // Pode persistir o novo valor
     }
});
    
02.09.2014 / 16:22