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-array
s 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).
res/values/
are processed for whatever's inside their<resources>
elements. You can certainly have apreferences.xml
file there, but its<string>
s,<array>
s, etc. will still be compiled into the sameR
classes as they always are. That is, your array's identifier isR.array.prefs_titles
, no matter which file it's in. – Mike M.