How to concatenate multiple strings in android XML? [duplicate] How to concatenate multiple strings in android XML? [duplicate] android android

How to concatenate multiple strings in android XML? [duplicate]


I've tried to do a similar maneuver myself but I was told this is not doable in Android.

The interesting thing is that you get an error message that indicates that it indeed is possible but due to errors in resource matching it's not possible right now. (Are you sure you have defined the "app_name" and "version_name" strings before the "title" and "title2" strings?)

You can however do something like:

<string name="title">%1$s test</string><string name="title2">%1$s %2$s</string><string name="app_name">AppName</string><string name="version_name">1.2</string>

And then from Java code do something like:

Resources res = getResources();String appName = res.getString(R.string.app_name);String versionName = res.getString(R.string.version_name);String title = res.getString(R.string.title, appName);String title2 = res.getString(R.string.title2, appName, versionName);

More about formatting strings in Android.

Hope this helps.