Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate Strings in the strings.xml file for Android

Tags:

java

android

xml

Is possible to concatenate a String already existing in strings.xml with the current one.
That is: If I have

<string name="hello">hello</string>

and I want to create a new string with the format "Your android says "+hello

like image 615
Addev Avatar asked Dec 02 '11 09:12

Addev


3 Answers

I am afraid that is not possible in strings.xml.

What you can do is create the final string programmatically using getString:

String outStr = getString(R.string.your_android_says) + 
  " " + getString(R.string.hello);
like image 200
havexz Avatar answered Oct 12 '22 01:10

havexz


Not sure if this is what you want:

String s = "Your android says" + getResources().getString(R.id.name);

What you could also do it like:

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

String androidsays = "Your android says";
String s = getString(R.id.name, androidsays);
like image 10
Maggie Avatar answered Oct 12 '22 01:10

Maggie


you can create any number of altered string , but bounded upto runTime memory only . you can't store persistently this new string like usually you do through values/string.xml .

example String newString = "something" + getResources().getString(id);

sharedPreferences in the way you can achieve this . store newly generated string into sharedpreferences and access later .

like image 2
Shailendra Singh Rajawat Avatar answered Oct 12 '22 02:10

Shailendra Singh Rajawat