0

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

Linh
  • 57,942
  • 23
  • 262
  • 279

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
  • 38,365
  • 12
  • 84
  • 104
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
  • 57,942
  • 23
  • 262
  • 279