4

This is what I want to do, in standard way.

<string name="foo">foo</string>
<string name="foo_bar">foo bar</string>

Can I rewrite like below?

<string name="foo">foo</string>
<string name="foo_bar">@string/foo bar</string>

I know this is not in schema, however, it is OK like below,

<string name="foo">foo</string>
<string name="altfoo">@string/foo</string>

Why!?

6
  • 1
    what you actully want to do??? Commented Feb 25, 2014 at 8:33
  • Yes you can do as the last one Commented Feb 25, 2014 at 8:35
  • 1
    see if this help : stackoverflow.com/questions/4161256/… Commented Feb 25, 2014 at 8:35
  • Sorry second example "foo_bar" should be @string/foo bar Commented Feb 25, 2014 at 8:36
  • I actually want second one. Commented Feb 25, 2014 at 8:41

1 Answer 1

2

This

<string name="foo">foo</string>
<string name="foo_bar">@string/foo bar</string>

wrong coz there is no resource with the name foo bar

The above would be right if you had

<string name="foo bar">foo and bar</string>
<string name="foo_bar">@string/foo bar</string>

This

<string name="foo">foo</string>
<string name="altfoo">@string/foo</string>

is right coz there is a resource with name foo and you are referencing the same

You may want to check

Concatenate Strings in the strings.xml file for Android

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

5 Comments

The link you point to actually says you can't do it like your answer... Have you really tried it?
@TactMayers what mistake are you pointing @?. You can try it and then inform
You can't write <string name="altfoo">@string/foo</string> and expect the string altfoo has the value foo. This will not work.
@TactMayers no it will work if you have <string name="foo">foo</string>. try it yourself
Alright... I misunderstood. If it's a direct reference it will work. But concatenation will not work.

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.