0

Android xml string item how to connect two item enter image description here

Linh
  • 51,033
  • 19
  • 228
  • 256

2 Answers2

1

If you have these strings:

<string name="a">Hello</string>
<string name="b">World</string>

Then in your Activity you would do this:

String a = getString(R.string.a);
String b = getString(R.string.b);
String c = a + " " + b;

Alternatively, you can add a third string and retrieve it this way:

<string name="c">%s %s</string>

String c = getString(R.string.c, a, b);
Karakuri
  • 37,627
  • 12
  • 79
  • 103
0

I think we can use string-array

<string-array name="c">
        <item> @string/a</item>
        <item> " " </item>
        <item> @string/b</item>
</string-array>

an in code

String c = Arrays.toString(getResources().getStringArray(R.array.c));
Linh
  • 51,033
  • 19
  • 228
  • 256