How to remove PreferenceCategory programmatically?

you can hide a category by getting reference to PreferenceScreen:

I your xml :

<PreferenceScreen 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:key="@string/preferenceScreen">

//set all you values
//Preference, PreferenceCategory and/or CheckBoxPreference

</PreferenceScreen>

in you string.xml :
don’t forgot to set this new string

 <string name="preferenceScreen" translatable="false">preferenceScreen</string>

in you code:

preferenceScreen = (PreferenceScreen) findPreference(getResources().getString(R.string.preferenceScreen));

and then remove the category from your PreferenceScreen :

myCategory = (PreferenceCategory) findPreference(getResources().getString(R.string.my_category));
myPreferenceScreen.removePreference(myCategory);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)