Updating preferences in real time

后端 未结 1 1183
无人及你
无人及你 2020-12-04 00:51

I have a Preferences Screen which has some prefs that are interconnected. Which means, if I have pref x and y, I sometimes need y to c

相关标签:
1条回答
  • 2020-12-04 01:50

    Try to call the setter of the preference itself instead updating it on your own:

    E.g. EditTextPreference.setText(). So the preference itself updates it's own value too. If you do the update on your own the preference will not fetch the new value because it doesn't even know that the persisted value has changed.

    If you have a PreferenceFragment, you can get the preference with PreferenceFragment.findPreference().

    If you have a PreferenceActivity, you can get the preference with PreferenceActivity.findPreference().

    You call that with the preference key you assigned in your settings XML file and you get an instance of the corresponding preference. Then you cast it to an CheckBoxPreference, EditTextPreference, etc (the type you set in your XML file).

    0 讨论(0)
提交回复
热议问题