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?

4
  • Can you paste the content of your app_name.xml file. This is not clear, we need more information to help you out. Commented Apr 5, 2012 at 12:47
  • It is very strange .. I am also shock..... Commented Apr 5, 2012 at 12:59
  • after cleaning the project and restart the emulator, it seems that the third line didnt work as well. Commented Apr 5, 2012 at 12:59
  • See also this question. Commented May 12, 2013 at 0:19

2 Answers 2

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));
Sign up to request clarification or add additional context in comments.

2 Comments

yeah thats the normal way to do :) but i want to edit only the xml file
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)
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.

1 Comment

yeah it seems so, tanks for your answer

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.