PreferenceFragment中的SwitchPreference正在重置值

时间:2013-10-05 00:53:23

标签: android android-fragments

我有一个带有几个SwitchPreferences的PreferencesFragment。

在极少数平板电脑上。我看到当一个开关设置为关闭并且用户将它们更改为打开时发生的问题,然后向下滚动以将SwitchPreference移动到屏幕外。当用户向上滚动时,开关已恢复为关闭状态。

例如,在下图中。如果用户将“启用背景”设置为“开”,则向下滚动。然后备份。 “启用背景”将再次关闭。有没有人知道为什么会在偶尔的设备上发生这种情况。

settings

这是特定SwitchPrefence

的xml
<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>

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

1 个答案:

答案 0 :(得分:3)

原来这实际上是一个google bug。

报告问题here