I want to create a string array in string.xml in values folder for my android application. How to do this.. can anybody help..
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="my_array">
<item>string1</item>
<item>string2</item>
<item>string3</item>
</string-array>
</resources>
Related
I have a question about values/strings.xml
I'd like to use strings.xml, but use another strings.xml file.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello!</string>
<string name="test">veeeeeeeeeeeeeeeeeeeeeeeery long script(about 1000characters)</string>
</resources>
like this, when I want to manage veeeeery long script by another xml file.
Then can I use another .xml file in values/strings.xml file?
for example like..
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello!</string>
<string name="test"> #values/script.xml </string>
</resources>
Thank you for reading my question.
Have a nice day :)
Yes, you just need to use #string instead of #values
How to add apostrophe in Android String Resource File?
Hi!,
I'm trying to add apostrophe (') in android strings
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Stack's Answers</string>
</resources>
Try:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Stack\'s Answers</string>
</resources>
You have to escape the XML with a \ before the apostrophe because it is a character that has a special meaning in Android's XML.
Try this way..
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Stack\'s Answers</string>
</resources>
Is something like this possible??
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="planets_array">
<item value=My >Mercury</item>
<item value=Vs >Venus</item>
<item value=EA >Earth</item>
<item value=Ms >Mars</item>
</string-array>
</resources>
the listView will show the planets but when the user selects Mars
the value I get will be Ms.
No, there is no such direct way to use string array in android app resources. One of my suggestion is separate the label and value to two different string arrays, then use these string arrays in your code.
<string-array name="planet_label">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
</string-array>
<string-array name="planet_values">
<item>My</item>
<item>Vs</item>
<item>Ea</item>
<item>Ms</item>
</string-array>
I am developing an android application and would like to be able to create an array consisting of words from an xml file, but am unsure of how that would look. Any help is appreciated.
You can do this if you just need a preset list
In your res/values folder there should be an arrays.xml file if there isnt create it.
Then withiin the file add something like this
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="myarray">
<item>first item</item>
<item>second item</item>
<item>third item</item>
<item>foruth item</item>
</array>
</resources>
then do access it do this
String[] text = getResources().getStringArray(R.array.myarray);
How can I do this?
<string-array name="#string/a_string_from_resources">
Is it possible to name a string-array using a string Resource?
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="#string/a_string_from_resources">
<item>first</item>
<item>second</item>
<item>third</item>
<item>fourth</item>
<item>fifth</item>
</string-array>
</resources>
<string-array name="array_name">
My guess is you cant! Because the R.java is generated from all the resources at the same time. As the xmls are meaningless before generating, resource files wont be able to gather the resources from themselves.