1

is it possible to use a sting in another string?

What I want is:

<string name="homepage">http://www.examplepage.com</string>
<string name="desc">Go to my Website: "string:"homepage"</string>

So, if I have more strings which should show my homepage, how do i deal with this if I not want to change every singel string, just the "homepage" string?

user3759834
  • 43
  • 1
  • 3
  • Where do you use these values ? – Shivam Verma Jun 20 '14 at 11:00
  • I use these in a XML File in my android project. And I want to show my homepage several times in the app. But if I want to change the URL I dont want to change every singel string. Just one – user3759834 Jun 20 '14 at 11:20
  • Well, you can't directly do this using XML only. Why not use strings inside Java where you can modify them. If you want to access it everywhere in your app, you can use SharedPrefences. – Shivam Verma Jun 20 '14 at 11:26

1 Answers1

0

You can do it like this:

<string name="homepage">http://www.examplepage.com</string>
<string name="desc">Go to my Website: %s</string>

and in app you have to use String.format :

Resources res = getResources();
String.format(res.getString(R.string.desc), res.getString(R.string.homepage));
Aleizdein
  • 404
  • 3
  • 9
  • here's some more info about formatting: [link](http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling) – Aleizdein Jun 20 '14 at 11:59