Question

I have an Android app, in which I use Preferences. They are grouped with PreferenceCategory's.

My PreferenceCategory's have keys (android:key="setting"), like the ones in the official tutorial for settings (which I used myself to learn & make mine).

But is this a recommended way of doing preferences, a convention, or does is just happen to be that way in the tutorial? I don't have to refer to most of the categories in my code, just the preferences inside, so I see no real reason to have keys with all of them.

Was it helpful?

Solution

But is this a recommended way of doing preferences, a convention, or does is just happen to be that way in the tutorial?

No, you don't need to set keys for your PreferenceCategories, if you're not doing anything with them.

You can add Preferences to your PreferenceCategory by accessing it with findPreference(your_preference_category_key) and then calling addPreference(...) on it. But since you're not doing that you don't need to set any key for it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top