在preferenceFragment开关preference正在重置值 [英] SwitchPreference in PreferenceFragment is resetting values

查看:383
本文介绍了在preferenceFragment开关preference正在重置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个preferencesFragment几个开关preferences。

在极少数平板电脑。我看到,当开关被设置为关闭,用户改变他们,然后向下滚动屏幕外移动交换机preference时出现的问题。当用户滚动备份交换机恢复到了。

作为一个例子,在以下的画面。如果用户设置启用背景幕布上,然后向下滚动。然后备份。 启用背景幕布将再次关闭。有谁知道这是为什么偶尔的设备上发生的事情。

下面是针对特定的交换机prefence的XML

 < preferenceCategory
    机器人:标题=常规
    机器人:关键=pref_general_settings>    <开关preference
        机器人:关键=pref_enable_backdrops
        机器人:标题=启用背景幕布
        机器人:summaryOff =背景幕布不能在不同的视图中显示的
        机器人:summaryOn =背景幕布显示在不同的视图
        机器人:设置defaultValue =FALSE/>    <开关preference
        机器人:关键=pref_include_trailers
        机器人:标题=包括拖车
        机器人:summaryOff =拖车将不包含在搜索结果中,主屏幕,和演员生物屏
        机器人:summaryOn =预告片将包含在搜索结果中,主屏幕,和演员生物屏
        机器人:设置defaultValue =FALSE/>< / preferenceCategory>

在preferencesFragment

 公共类MainSettingsFragment扩展$ P $ {pferenceFragment@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);    加preferencesFromResource(R.xml preferences);    尝试{
        文件实用程序文件实用=新文件实用程序();        ServerInfo serverInfo = fileUtils.LoadLastConnected(getActivity());        如果(serverInfo!= NULL){
            如果(serverInfo.FriendlyName = NULL&放大器;!&安培;!serverInfo.FriendlyName.isEmpty())
                this.find preference(pref_server_name)的setTitle(serverInfo.FriendlyName)。
            其他
                this.find preference(pref_server_name)的setTitle(serverInfo.HostNameOrIpAddress)。
        }    }赶上(例外五){
        // 做一点事
    }
}
}


解决方案

原来,这其实是一个谷歌的错误。

问题报道这里

I have a PreferencesFragment with several SwitchPreferences.

On a very few tablets. I'm seeing an issue that occurs when a switch is set to off and the user changes them to on, then scrolls down moving the SwitchPreference offscreen. When the user scrolls back up the switch has reverted back to off.

As an example, in the following picture. If the user sets "Enable Backdrops" to on, then scrolls down. Then back up. "Enable Backdrops" will be off again. Does anyone know why this is happening on the occasional device.

Here is the xml for that particular SwitchPrefence

<PreferenceCategory
    android:title="General"
    android:key="pref_general_settings">        

    <SwitchPreference
        android:key="pref_enable_backdrops"
        android:title="Enable Backdrops"
        android:summaryOff="Backdrops are not shown in various views"
        android:summaryOn="Backdrops are shown in various views"
        android:defaultValue="false" />

    <SwitchPreference
        android:key="pref_include_trailers"
        android:title="Include Trailers"
        android:summaryOff="Trailers will not be included in search results, the homescreen, and actor bio screens"
        android:summaryOn="Trailers will be included in search results, the homescreen, and actor bio screens"
        android:defaultValue="false" />

</PreferenceCategory>

The PreferencesFragment

public class MainSettingsFragment extends PreferenceFragment {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.preferences);

    try {
        FileUtils fileUtils = new FileUtils();

        ServerInfo serverInfo = fileUtils.LoadLastConnected(getActivity());

        if (serverInfo != null) {
            if (serverInfo.FriendlyName != null && !serverInfo.FriendlyName.isEmpty())
                this.findPreference("pref_server_name").setTitle(serverInfo.FriendlyName);
            else
                this.findPreference("pref_server_name").setTitle(serverInfo.HostNameOrIpAddress);
        }

    } catch (Exception e) {
        // Do Something
    }
}
}

解决方案

Turns out this is actually a google bug.

Issue reported here

这篇关于在preferenceFragment开关preference正在重置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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