0

I can't solve this problem. I have preference screen and there is sub-preference that opens up another screen. On that another screen change of items can be caught with OnSharedPreferenceChangeListener and I change summary in parent preference screen, but when I go back to that parent preference screen, summary did not changed.

Same question was asked here, but conclusion was not clear, and I could not solve this problem. It seems a common problem to me and I guess there is good solution for this.

Dose anyone know a solution for this problem?

  • There is one thing I like to keep: sub-preference is standard one, not custom.
Community
  • 1
  • 1
Tomcat
  • 1,405
  • 3
  • 22
  • 37

2 Answers2

4

I've solved this by adding OnPreferenceClickListener to the preferences which will change the summary in the main screen.

OnPreferenceClickListener viewUpdater = new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            updateView();
            return  false;
        }
    };

Within the updateView() method I'm setting the summary to a new value and then I'm using the invalidateViews method of the preferences listview to trigger an update of the displayed summary

private void updateView() {
    preference.setSummary(newSummary);
    getListView().invalidateViews();
}
Nikhil
  • 16,194
  • 20
  • 64
  • 81
senola
  • 782
  • 4
  • 12
0

Check the answer of @jmbouffard that's work for me

Community
  • 1
  • 1
Yahia
  • 691
  • 1
  • 7
  • 24