Is concatenation of resource strings/string concatenation, possible in layout file?
Question : Is string concatenation possible in layout file?
Nope as far as I know.
One solution is to use what @DIVA has answered before.
Another possible solution is to create a custom view that extends TextView (or the view you want to achieve this) and create a custom attribute custom:concatenate
which receives a string reference and perform the concatenation automatically. IMHO I think this is the most clean approach.
In code will look as this:
<com.whatever.ConcatenateTextView
android:text="@string/whatever"
custom:concatenate="@string/second_string"/>
Or… you can use the power of Drawables creating a custom TextDrawable (which is explained very well by @Devunwired in this post and the concrete implementation of it in Github).
Copying what @Devunwired has said in his post about it:
With this class, text can now be part of the Drawable world, meaning it can not only be set alone in places where you would normally put an image, it can also be placed together with other Drawables in containers like StateListDrawable or animated with the likes of TransitionDrawable and ClipDrawable. In many cases, we can use this to do a job that would otherwise require multiple views or compound controls just to achieve a given visual effect; thus it can reduce overhead in your view hierarchy.
This combined with your custom TextView as I explained before (or whatever view you want to use) gives you a very powerful option. Again copying the example that @Devunwired wrote in his post:
ImageView mImageOne;
TextDrawable d = new TextDrawable(this);
d.setText("SAMPLE TEXT\nLINE TWO");
d.setTextAlign(Layout.Alignment.ALIGN_CENTER);
mImageOne.setImageDrawable(d);
If you need more help please let me know in the comments and I'll gladly update the answer!
Using XML entities it's possible to use the same string multiple places within an XML file:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE resources [
<!ENTITY appname "MrQuery">
<!ENTITY author "Oded">
]>
<resources>
<string name="app_name">&appname;</string>
<string name="description">The &appname; app was created by &author;</string>
</resources>
I used this answer: dynamic String using String.xml?