tags:

views:

53

answers:

1

Android allows to create aliases of resource strings like:

<resources>
 <string name="foo">somestring</string>
 <string name="bar">@string/foo</string>
</resources>

by which the resource "bar" becomes an alias for the resource named "foo".

What I would for my app is a possibility to combine an existing resource prefix with different suffixes, i.e. to extend it like:

<resources>
 <string name="foo">foo</string>
 <string name="bar">@string/foo+bar</string> 
 <string name="else">@string/foo+else</string> 
</resources>

where the resource "bar" would yield the string "foobar". Its clear that '+' doesn't work here but is there some other option to achieve such a string concatenation, so that one could define a bunch of string resources that have a common prefix?

I realize of course that I could do such resource string concatenation at runtime but defining them statically in the resources would seem so much more elegant and simpler.

Michael

A: 

No, it's not possible. You can just use <string name="bar">This is my %s</string> and then use String.format() in your app to fill in the variable with for example

getResources().getString(R.string.foo);
Mathias Lin