How do I get the PreferenceCategory of a Preference? PreferenceManager has a findPreference method but a Preference does not have a getCategory method.
Is there a way to get the PreferenceCategory of a Preference from it's key name?
How do I get the PreferenceCategory of a Preference? PreferenceManager has a findPreference method but a Preference does not have a getCategory method.
Is there a way to get the PreferenceCategory of a Preference from it's key name?
Are you trying to do this from within the PreferenceActivity or elsewhere? If from there, try this out. It should loop through your categories and find the right one. Just make sure you update the catKeys array to include the categories you want to search each time you change your xml.
String catKeys = {"catOne","catTwo","catThree","catFour"};
String getCategoryKey(String prefKey)
{
PreferenceCategory curCat;
Preference test;
for(String catKey : catKeys)
{
curCat = (PreferenceCategory)findPreference(catKey);
if(curCat == null)
continue;
test = curCat.findPreference(prefKey);
if(test != null)
return catKey;
}
}
I don't see a getCategory or getGroup neither in Preference.
But, you can use the methods of PreferenceCategory inherited from http://developer.android.com/reference/android/preference/PreferenceGroup.html
getPreference(int index)
int getPreferenceCount()
That's a long way indeed for what you want to do, but it looks like you should rebuild the preference menu indeed.
Other alternative would be to saxp your xml prefrence file.
Regards, Stéphane