Which method is triggered when changing a value in the Preferenceactivity class?

Asked

Viewed 57 times

1

I would like to capture the user changed field in a class that inherits from Preferenceactivity.

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

  • Herik, you want to listen for the value exchange of a subclass of Preference (given its instance), or wants to listen for any change of value (for any Preference)? You want to do inside the PreferenceActivity or outside?

  • It would be inside my activity that inherits from Preferenceactivity, in this case I want to take a specific Preference. As defined in xml: <Edittextpreference android:key="erp_cod_seller"/>

1 answer

2


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

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

To be notified of the change in 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
     }
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.