3

I am working on a project that includes a lot of strings and string arrays. I would like to put them into created folders inside res/values, but I get errors when I try to do this. Either getRecources() does not recognize the new folder or the xml attributes cannot link together. I know this is a noob-ish question, but thanks for the help!

1
  • 1
    You cannot have subfolders. However you can split your strings and string arrays into multiple files (e.g. strings1.xml, strings2.xml). Commented Jun 28, 2013 at 22:12

3 Answers 3

3

Unfortunately, you can't create any subfolders in your values folder. But you have two instruments to control the hierarchy.

String arrays are declared in the following way:

<string-array name="arr_name">
    <item>Text</item>
    <item>Another text</item>
</string-array>

You can access them through R.array.arr_name.

Prefixes are kind of obvious, but since you mentioned that you are a novice, it's worth mentioning. I usually prefix all of my strings depending on how they are used. For example, btn_ for the text used on buttons, dialog_ for strings used in dialogs and so on. This way autocomplete in the IDE also works much better too.

Also you can split your declarations into different files, but this doesn't have any impact at all on the way you access them, so I don't know if this can help you.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this is what I have started to find myself doing. Thanks again for the help. Greatly appreciate it.
0

You can define array of strings using following way. Later you can access it in code with R.values.langs

<string-array name="langs">
    <item>бг</item>
    <item>en</item>
    <item>ру</item>
</string-array>

Comments

0

To organise my res folder I use defined xml files not sub-folders.

Basic Example:
- if you have Strings for your Login Page put them in login_strings.xml
- if you have Strings for your Options Page put them in options_strings.xml etc.

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.