开发者

How to update summary of preference from sub-preference

开发者 https://www.devze.com 2023-02-09 11:01 出处:网络
I can\'t solve this problem. I have preference screen and there is sub-preference th开发者_运维知识库at opens up another screen. On that another screen change of items can be caught with OnSharedPrefe

I can't solve this problem. I have preference screen and there is sub-preference th开发者_运维知识库at 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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消