2

I've got a setting screen with preferences in my app.

I use PreferenceFragmentCompat and usual AppCompatActivity. When I change state of some preference(f.e. SwitchPreferenceCompat) and tap on it then the Android preference framework will change its internal state and upgrade preference UI. Thats pretty good.

In one usecase I have to change internal preference state manually and then I must change preference UI manually but I didn't find any invalidate-method to upgrade preference-UI.

I load preference screen with its children and them states in onCreatePreferences

override fun onCreatePreferences(bundle: Bundle?, rootKey: String?) {

    setPreferencesFromResource(R.xml.preferences, rootKey)

}

but when I return on that screen(after another activity is finished) I should refresh preference-UI according to its new internal state.

Is there anyone who khows how to do it manually (I'm aware that this workflow is not native)?

Alex Zezekalo
  • 1,031
  • 2
  • 17
  • 34
  • 1
    Possible duplicate of [How do you refresh PreferenceActivity to show changes in the settings?](http://stackoverflow.com/questions/8003098/how-do-you-refresh-preferenceactivity-to-show-changes-in-the-settings) – avalancha May 11 '16 at 07:42
  • try overriding onPreferenceChanged() method – akhil Rao May 11 '16 at 07:51
  • I use the descendants of PreferenceFragmentCompat and usual AppCompatActivity. – Alex Zezekalo May 11 '16 at 07:56
  • Yes, I can manually change SwitchPreferenceCompat state by setting setChecked(true/false) to it. But the last problem is when should I call it, in what callback?! When I setup listener(setOnPreferenceChangeListener) to SwitchPreferenceCompat-object then it isn`t fired! Now I call update in onStart but I think it's not the best solution. – Alex Zezekalo May 11 '16 at 09:10

0 Answers0