Gerald Eersteling
Gerald Eersteling

Reputation: 1284

Use a reference to a String resource as a name attribute for other resources

Is it possible to create an resource in XML where the name attribute references to a String resource?

Let me show an example:

In my strings.xml I have:

<string name="some_string">I am a string</string>

Can I (in some way) use the String resource as a name for another resource? As in:

<integer name="@string/some_string">1</integer>


To clarify some things:

<string name="another_string">@string/some_string</string>

<integer name=@string/some_string>1</integer>

Upvotes: 2

Views: 285

Answers (2)

user957654
user957654

Reputation:

As mentiond in the documentation of the More Resource Types :

name : String. A name for the string. This name will be used as the resource ID.

so you cant do this .

hope that helps

Upvotes: 1

Simulant
Simulant

Reputation: 20102

I don't think this will ever work.

Also this would be a very bad idea, because the value of your String can change by translations to other languages. Following this the name (ID) of your integer would change by using your App in different countries. This could break your code by changing the Phones default language.

Upvotes: 2

Related Questions