Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>edit:</strong> I've been having trouble getting this to work as you requested. I read through the source for <code>Preference</code>s and how they handle state without any luck, so I'm probably missing something obvious (isn't that how it often goes?)</p> <p>I did some testing, and I believe that the state of the <code>PreferenceScreen</code> and/or the <code>Dialog</code> it uses to display the nested <code>PreferenceScreen</code> is behaving in a way that neither of us expects. This behavior is not observed when using a <code>PreferenceCategory</code> instead of a <code>PreferenceScreen</code>, for example.</p> <h2>Since this way of working with <code>Preference</code>s is deprecated, you can always try using fragments:</h2> <blockquote> <p><a href="http://developer.android.com/reference/android/preference/PreferenceActivity.html" rel="nofollow noreferrer">http://developer.android.com/reference/android/preference/PreferenceActivity.html</a></p> </blockquote> <p>However, I suspect you are avoiding this for legacy reasons.</p> <h2>Another option would be to create your <code>Preference</code> programmatically:</h2> <p><a href="https://stackoverflow.com/questions/12551854/building-preference-screen-in-code-depending-on-another-setting?rq=1">Building Preference screen in code depending on another setting</a></p> <h2>Or, you could handle configuration changes yourself:</h2> <pre><code>http://developer.android.com/reference/android/app/Activity.html#ConfigurationChanges https://stackoverflow.com/questions/3542333/how-to-prevent-custom-views-from-losing-state-across-screen-orientation-changes/8127813#8127813 &lt;activity .. android:configChanges="orientation|keyboardHidden" .. &gt; </code></pre> <p>Hopefully you get this figured out soon. I'm sure the solution will pop out at us eventually; it can't be that hard! <em>Here's hoping</em> ;)</p> <p><strong>Original source (mostly) retained below:</strong></p> <pre><code> package com.example.removepref; import android.preference.Preference; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceActivity; import android.preference.PreferenceScreen; import android.util.Log; public class PrefSubscreenActivity extends PreferenceActivity { /** * Preference keys. */ private static final String PREFERENCE_TO_CLICK = PrefFlatActivity.PREFERENCE_TO_CLICK; private static final String PREFERENCE_TO_REMOVE = PrefFlatActivity.PREFERENCE_TO_REMOVE; private static final String PREFERENCE_SUBSCREEN = "subscreen"; private final String PREF_NAME = getClass().getName() + ".pref"; @Override protected void onResume() { super.onResume(); getPreferenceManager().setSharedPreferencesName(PREF_NAME); addPreferencesFromResource(R.xml.pref_subscreen); findPreference(PREFERENCE_TO_CLICK).setOnPreferenceClickListener(new OnFlatClickListener()); } /** * Removes or adds Preference with key PREFERENCE_TO_REMOVE when clicked. */ private class OnFlatClickListener implements OnPreferenceClickListener { private Preference mRescuedPreference; private boolean mPrefToRemoveVisible = true; public boolean onPreferenceClick(Preference preference) { // toggle visibility mPrefToRemoveVisible = !mPrefToRemoveVisible; PreferenceScreen screen = (PreferenceScreen) findPreference(PREFERENCE_SUBSCREEN); Preference prefToRemove = screen.findPreference(PREFERENCE_TO_REMOVE); Log.d("test", "Found PREFERENCE_TO_REMOVE: " + (prefToRemove != null)); Log.d("test", "And noted mPrefToRemoveVisible: " + mPrefToRemoveVisible); //Replaced the conditional blocks: if (mPrefToRemoveVisible &amp;&amp; null == prefToRemove) { boolean added = screen.addPreference(mRescuedPreference); Log.d("test", "screen.addPreference(mRescuedPreference) success?" + added); } else if (!mPrefToRemoveVisible &amp;&amp; null != prefToRemove) { mRescuedPreference = prefToRemove; boolean removed = screen.removePreference(prefToRemove); Log.d("test", "screen.removePreference(mRescuedPreference) success?" + removed); } return true; } } } </code></pre> <p>Recommended Reading: <a href="http://developer.android.com/guide/topics/resources/runtime-changes.html" rel="nofollow noreferrer">http://developer.android.com/guide/topics/resources/runtime-changes.html</a></p>
    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. VO
      singulars
      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