Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to reference another string in strings.xml? [duplicate]

Is it possible to reference one string in strings.xml inside another string that contains other text?

Something that is allowed in XML, and would achieve this effect:

<string name="string_one">My string</string>
<string name="string_two">Here it is: android:id="@string/string_one"</string>
like image 564
ChaimKut Avatar asked May 03 '10 10:05

ChaimKut


People also ask

What is the purpose of string XML?

A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String. XML resource that provides a single string.

How to add special characters in string XML in android?

To include special characters inside XML files you must use the numeric character reference instead of that character. The numeric character reference must be UTF-8 because the supported encoding for XML files is defined in the prolog as encoding="UTF-8" and should not be changed.

Where is the strings XML file located?

The XML resource files containing localized strings are placed in subfolders of the project's res folder. Android uses a special folder-naming scheme to automatically choose the correct localized resources—for example, the folder values-fr would contain a strings.


1 Answers

I don't think it's possible. What I usually do is the following:

<string name="string_one">My string</string>
<string name="string_two">Here it is: %s" </string>

and in the java code:

String.format(getString(R.string.string_two), getString(R.string.string_one));

I do this kind of thing for parametrize msgs like: "You have %d new mails".

like image 153
Macarse Avatar answered Sep 22 '22 08:09

Macarse