2

i am using Eclipse 3.7.2.

I dont know why but the last line leads to an error highlightning

<string name="app_name">Test</string>
<string name="title">@string/app_name</string> <!-- works //-->
<string name="txt_text">Checkout @string/app_name this works</string> <!-- works //-->
<string name="txt_recommend">@string/app_name is not working</string> <!-- error //-->

is there a work around?

Mario
  • 758
  • 12
  • 25

2 Answers2

6

I believe you can't mix references and text in the XML. Use formatting placeholders instead.

http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling

Instead of

<string name="app_name">Test</string>
<string name="txt_recommend">@string/app_name is not working</string>

this would look like

<string name="app_name">Test</string>
<string name="txt_recommend">%s is not working</string>

And in the code:

String text = String.format(res.getString(R.string.txt_recommend), res.getString(R.string.app_name));
mattanja
  • 1,442
  • 14
  • 21
  • yeah thats the normal way to do :) but i want to edit only the xml file – Mario Apr 05 '12 at 13:00
  • but I can't find an example referencing other resources in XML now - I doubt it's possible but can't test right now. That's propably why your third line now doesn't work either. (I guess you can't rely on the eclipse output alone in this case) – mattanja Apr 05 '12 at 13:10
0

The error is probably from the second last line rather than the last line.

<string name="txt_text">Checkout @string/app_name this works</string>

In this line you seem to be mixing text ("Checkout" and "this works" ) with a reference ("@string/app_name")

I dont think you can do that just in xml.

Mel
  • 6,214
  • 10
  • 54
  • 71