Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can get value to PreferenceFragment

I have this code:

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

now i need to get Checkbox value in FragmentA:

sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());

and now?

like image 849
user1608228 Avatar asked Nov 05 '14 09:11

user1608228


2 Answers

sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
boolean isChecked = sharedPreferences.getBoolean(getString(R.string.notification_settings), false);
like image 154
Hoan Nguyen Avatar answered Nov 07 '22 17:11

Hoan Nguyen


Try this way,hope this will help you to solve your problem.

sharedPreferences.getBoolean("notification_settings",false)

getBoolean() : required two parameter one is key and another is default value

like image 30
Haresh Chhelana Avatar answered Nov 07 '22 17:11

Haresh Chhelana