0
votes

I'm attempting to create a 'Preferences' Activity for my Wear OS app (home-baked as I don't believe the standard Settings Activity copes with round screens).

In order to support the round screen I am planning to use a WearableRecyclerView and so need to define string-arrays for the contents of the Recycler layouts.

To keep things clean in my code, I'd like to keep these string-arrays out of my strings.xml files if possible.

Therefore, is it possible to use, for example, preferences.xml in the res/values folder (and provide translations in the values-?? folders) and then reference this in code?

I have tried creating preferences.xml but when I try to retrieve the arrays with

String[] prefsTitlesArray = getResources().getStringArray(R.preferences.prefs_titles);

I get an error flagged in the IDE as 'preferences' isn't recognised under R.

Do I have to stick to the standard .xml file names such as strings.xml and array.xml or is it possible to use an arbitrary file name under the values tree to keep thinsg nice and clean and obviously named?

(Note, I have looked at Is it possible to create translateable arbitrary XML resources in Android Studio? which seems to imply that arbitrary xml file names might be possible outside of the values tree, but doesn't mention how they are referenced in code (Java, in my case).

The file names don't matter; you can name them whatever you like. All of the files in res/values/ are processed for whatever's inside their <resources> elements. You can certainly have a preferences.xml file there, but its <string>s, <array>s, etc. will still be compiled into the same R classes as they always are. That is, your array's identifier is R.array.prefs_titles, no matter which file it's in.Mike M.
Thanks MIke, I didn't realise that. If you put that in an answer I'll accept it.Fat Monk
Oh, I'm good. :-) Nothin' huge. Thanks, though. I appreciate the offer. Cheers!Mike M.