Note that there are some explanatory texts on larger screens.

plurals
  1. POPreferenceActivity Screen
    primarykey
    data
    text
    <p>I'm working on my settings as you can see from my xml and class. my onPreferenceChange is not setting the 2nd and 3rd toggle buttons to false when the first 1st toggle button is set to false.</p> <p>Logcat</p> <pre><code>07-23 16:10:42.879: I/PROJECTCARUSO(11579): preference: Cervical Mucus Are you observing MucusnewValue: true 07-23 16:10:42.879: I/PROJECTCARUSO(11579): True 07-23 16:10:44.601: I/PROJECTCARUSO(11579): preference: Cervical Mucus Are you observing MucusnewValue: false 07-23 16:10:44.611: I/PROJECTCARUSO(11579): True </code></pre> <p>Class:</p> <pre><code>public class UserSettingActivity extends PreferenceActivity implements OnPreferenceChangeListener{ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } /** * Populate the activity with the top-level headers. */ @Override public void onBuildHeaders(List&lt;Header&gt; target) { Log.i("PROJECTCARUSO","onBuildHeaders"); loadHeadersFromResource(R.xml.preference_headers, target); } /** * This fragment shows the preferences for the first header. */ public static class Prefs1Fragment extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.notification_settings); } } /** * This fragment shows the preferences for the second header. */ public static class Prefs2Fragment extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.charting_settings); findPreference("cervical_mucus").setOnPreferenceChangeListener( new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Log.i("PROJECTCARUSO","preference: "+ preference + "newValue: " + newValue); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); // string test w/o "==" usage. if ("false".equals(newValue)) { prefs.edit().putBoolean("mucus_stamps", false).commit(); prefs.edit().putBoolean("fertile_infertil", false).commit(); } else { prefs.edit().putBoolean("mucus_stamps", true).commit(); prefs.edit().putBoolean("fertile_infertil", true).commit(); } // remove all and reload getPreferenceScreen().removeAll(); //NAMEOFXML is the same you have in your fragement's oncreate addPreferencesFromResource(R.xml.preference_headers); // true instead of false so the new value gets kept return true; }; }); } } protected void onPause() { super.onPause(); } protected void onResume() { super.onResume(); } protected void onStop() { super.onStop(); finish(); } @Override public boolean onPreferenceChange(Preference arg0, Object arg1) { // TODO Auto-generated method stub return true; } } </code></pre> <p>XML:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;PreferenceCategory android:title="@string/pref_chart_profile" android:textSize="20px"&gt; &lt;SwitchPreference android:title="@+string/pref_symptothermal" android:summary="@+string/pref_symptothermal_summary" android:key="symptothermal" android:defaultValue="true" android:layout="@layout/pref_layout"/&gt; &lt;SwitchPreference android:id="@+id/cervical_mucus" android:title="@+string/pref_cervical_mucus" android:summary="@+string/pref_cervical_mucus_summary" android:key="cervical_mucus" android:defaultValue="true" android:layout="@layout/pref_layout" /&gt; &lt;SwitchPreference android:id="@+id/mucus_stamps" android:title="@+string/pref_mucus_stamps" android:summary="@+string/pref_mucus_stamps_summary" android:key="mucus_stamps" android:defaultValue="true" android:layout="@layout/pref_layout" /&gt; &lt;SwitchPreference android:id="@+id/fertile_infertil" android:title="@+string/pref_fertile_infertile" android:summary="@+string/pref_fertile_infertile_summary" android:key="fertile_infertil" android:defaultValue="true" android:layout="@layout/pref_layout" /&gt; &lt;/PreferenceCategory&gt; &lt;/PreferenceScreen&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload