Reputation: 1723
I've this EditTextPreference
<EditTextPreference
android:title="@string/settings_server"
android:summary="@string/server_name_message"
android:persistent="false"
android:key="SERVER_NAME" />
But with persistent="false" it does not call onSharedPreferenceChanged
method.
How can I detect this event keeping android:persistent="false"
Upvotes: 1
Views: 580
Reputation: 38223
You'll have to attach custom listener in code of your PreferenceActivity
or PreferenceFragment
:
EditTextPreference prefServerName = (EditTextPreference) findPreference("SERVER_NAME");
prefServerName.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String value = (String) newValue;
// do what you need
return true; // indicates you processed the new value
}
});
Upvotes: 4