【发布时间】:2014-11-05 09:46:23
【问题描述】:
我有这个代码:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference android:key="notification_settings"
android:text="@string/impostazione"
android:id="@+id/save_check"
android:summary="@string/notification_title"
android:defaultValue="false"
></CheckBoxPreference>
</PreferenceScreen>
现在我需要在 FragmentA 中获取 Checkbox 值:
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
现在呢?
【问题讨论】:
-
试试这个方法:sharedPreferences.getBoolean("notification_settings",false)
-
我有defaultValue,为什么我又设置为false?
-
getBoolean() 是必需的两个参数一个是键另一个是默认值。
-
谢谢!!!我不能投票给你评论,在“答案”中重写这个并我标记:D
标签: java android android-studio sharedpreferences