-3

I have 2 string resouces file:

<string name="label_1">Dumb1</string>
<string name="label_2">Dumb2</string>

In TextView, I want TextView shows static text: Dumb1Dumb2. How I do it in XML layout file without define a new String resouce? Can I do it? Thanks everyone!

Sometimes, I must use many static strings such as: Name: and Name (and more such type of string). So, how to avoid it? can I define Name and :, and set in xml: Name:?

Kingfisher Phuoc
  • 8,052
  • 9
  • 46
  • 86

2 Answers2

1

You can't have the same "key" for strings. use this:

<string name="label_1">Dumb1</string>
<string name="label_2">Dumb2</string>

P.S. You can also reference a string from another string using:

<string name="label_2">@string/label_1</string> 
Sean
  • 5,176
  • 2
  • 34
  • 50
1

You cant do that. If you want to show both strings, you have to solve it programmatically:

Resources res = myActivity().getResources();
myTextView.setText(res.getString(R.string.label_1) +
                        res.getString(R.string.label_2));

But according to this post: Reference one string from another string in strings.xml?, you can use Format.

Community
  • 1
  • 1
danijoo
  • 2,823
  • 4
  • 23
  • 43