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.
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
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);
I want to support multiple languages in my app using sqlite database and xml resources.
For example, the user can insert transaction objects. Each transaction has a category.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="categories">
<item>#string/category1</item>
<item>#string/category2</item>
<item>#string/category3</item>
<item>#string/category4</item>
<item>#string/category5</item>
</array>
</resources>
What is the correct approach to use the above values in sqlite? Should a table be created or I can use them directly from xml?
If I want the user to be able to also add his own categories, how the multi-language thing should work?
Please read the two following google guides about supporting different languages and localizing:
http://developer.android.com/training/basics/supporting-devices/languages.html
http://developer.android.com/guide/topics/resources/localization.html
the normal way is to create a strings.xml for every language:
For Storing your categories in your SQLite Database you should enumerate your Categories and store only the numbers, so you are independent of the spelling. Adding a user defined Catergory should also work this way.
MyProject/
res/
values/
strings.xml
values-es/
strings.xml
/values/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">My Application</string>
<string name="hello_world">Hello World!</string>
</resources>
/values-es/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">Mi AplicaciĆ³n</string>
<string name="hello_world">Hola Mundo!</string>
</resources>
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>