如何从子偏好更新偏好摘要 [英] How to update summary of preference from sub-preference

查看:43
本文介绍了如何从子偏好更新偏好摘要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法解决这个问题.我有偏好屏幕,并且有打开另一个屏幕的子偏好.在那个屏幕上,可以使用 OnSharedPreferenceChangeListener 捕获项目的另一个屏幕更改,并且我更改了父首选项屏幕中的摘要,但是当我返回到该父首选项屏幕时,摘要没有改变.

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?

  • 我喜欢保留一件事:子偏好是标准的,而不是自定义的.

推荐答案

我通过将 OnPreferenceClickListener 添加到首选项中解决了这个问题,这将更改主屏幕中的摘要.

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

在 updateView() 方法中,我将摘要设置为一个新值,然后我使用首选项列表视图的 invalidateViews 方法来触发显示摘要的更新

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

这篇关于如何从子偏好更新偏好摘要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆