On Jun 23, 10:56 pm, fry <[email protected]> wrote:
> Hi,
>
> Is it possible to store strings values in multiple files? Eg,
> strings.xml, strings1.xml, strings2.xml etc.
>
> I do not mean localized versions of the same file - those multiple
> files should contain different string ids in the same language, so in
> code they would be refered like:
>
> R.strings1.my_string_1
> R.strings1.my_string_2
> R.strings2.my_string_3
> etc.

As far as i know, the file name doesn't matter. You can have multiple
strings-n.xml files, but they all will still be refered as
R.strings.my_string.

It's not the file name that decides the part between R and the string
identifier, it's the xml element.

Scroll down to "Strings and Styled Text"
http://developer.android.com/guide/topics/resources/available-resources.html

It says: "Resource source file location: res/values/strings.xml (file
name is arbitrary)"

For example:
<resources>
   <string name="simple_welcome_message">Welcome!</string>
   <string name="styled_welcome_message">We are <b><i>so</i></b> glad
to see you.</string>
</resources>

the <string ...> element decides the part after R. and you can't
change that.

> So, "strings1", "strings2", "strings3" would be a kind of namespace
> for them.
>
> Or, another way is to have multiple R classes inside one project,
> which would deal with different stringsXXX.xml files.
>
> Like, currently we can refer to "my.name.space.R" and to "android.R"
> at the same time, so is it possible to have:
>
> android.R
> my.name.space1.R
> my.name.space2.R
> etc
>
> at the same time inside single project?
iirc you can't do that neither. More interesting question would be:
Why would you need seperated namespaces for resources? usually this
can be done in one single R file and have all the strings in
R.strings. Maybe you're just having some bad design which can be
solved otherwise? like i.e. by selecting proper naming of your string
resource ids?

Instead of having
R.string.name_label
R.string.surname_label

you could have
R.string.label_name
R.string.label_surname
etc.
or even
R.string.activity1_label_name
R.string.activity1_label_surname etc.

This would make it much easier to organize a big amount of strings
than using multiple R.xxx.my_string instances (which could also lead
to error, if you swap R.string1.my_string1 with R.string2.my_string1.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to