1
我有一個包含多個SwitchPreferences的PreferencesFragment。PreferenceFragment中的SwitchPreference正在重置值
在很少的平板電腦上。我看到一個問題,當一個開關被設置爲關閉狀態並且用戶將其改變爲開啓,然後向下滾動將SwitchPreference移出屏幕外時發生。當用戶向後滾動時,交換機已恢復爲關閉狀態。
作爲一個例子,在下面的圖片。如果用戶將「啓用背景」設置爲打開,則向下滾動。然後備份。 「啓用背景」將再次關閉。有誰知道爲什麼偶爾會出現這種情況。
這裏是特定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>
XML中的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
}
}
}