46

I am currently creating an application that have some strings (>300 for now) and I have some problems to quickly find a string with so many of them. So I was considering the possibility of using several string.xml files instead of only one (string_menu, string_activity1, ...).

Is there any side-effect with this practice? Is it a bad or a good practice?

I ask this because it seems that no many people on the net are using this possibility. So maybe there is some problem with it?

Sufian
  • 6,405
  • 16
  • 66
  • 120
sam
  • 3,441
  • 2
  • 33
  • 42

2 Answers2

55

As stated in the documentation you can use whatever filename you want:

The filename is arbitrary. The <string> element's name will be used as the resource ID.

chrulri
  • 1,822
  • 14
  • 16
  • i am currently talking about the file name, the string.xml file – sam Dec 17 '12 at 21:38
  • in fact my question is : is there any side-effect ? – sam Dec 17 '12 at 21:44
  • 17
    There are no side-effects. You can access all strings in the same way: `R.string.textname` – chrulri Dec 17 '12 at 21:45
  • 1
    Apparently the resource compiler looks for and identifies all string resources, regardless of file name. You can partition your strings into multiple files and keep the references as R.string... – Peri Hartman Jul 07 '15 at 15:32
15

There may be negligible side effects in performance, you can add as much as you can. I have 3 activity files MainActivity, PhotoActivity, UserActivity, create a common strings.xml file and other activity related files.

-strings.xml                    -> create common string values here.
  --strings_main.xml            -> create main activity specific string values here.
  --strings_photo.xml           -> ...
  --strings_user.xml            -> ... etc etc

Hope this is helpful. Thanks!

Madan Sapkota
  • 25,047
  • 11
  • 113
  • 117