How to update summary of preference from sub-preference

馋奶兔 提交于 2020-01-06 06:01:36

问题


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.

回答1:


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();
}



回答2:


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



来源:https://stackoverflow.com/questions/4933944/how-to-update-summary-of-preference-from-sub-preference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!