Remove/hide a preference from the screen
If your Preference
is within a PreferenceCategory
, you have to do this:
XML:
<PreferenceCategory
android:key="category_foo"
android:title="foo">
<CheckBoxPreference
android:key="checkPref" />
Java:
CheckBoxPreference mCheckBoxPref = (CheckBoxPreference) findPreference("checkPref");
PreferenceCategory mCategory = (PreferenceCategory) findPreference("category_foo");
mCategory.removePreference(mCheckBoxPref);
Yes, if you have a reference to both the Preference
, and its parent (a PreferenceCategory
, or PreferenceScreen
)
myPreferenceScreen.removePreference(myPreference);