For example if I have the following String_Array
<string-array name="recipe_ingredients">
<item>#array/m1_ingredients</item>
<item>#array/m2_ingredients</item>
</string-array>
How can I access #array/m1_ingredients where it is another String_Array
EDIT :
No, every item of a StringArray must always be a String, of course. So it can't be another StringArray
check the Documentation on resources, scroll to StringArray
name
String. A name for the array. This name will be used as the resource ID to reference the array.
here's an eg
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="planets_array">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
</string-array>
</resources>
This application code retrieves a string array:
Resources res = getResources();
String[] planets = res.getStringArray(R.array.planets_array);
Related
I have a ArrayList in my strings.xml. I would like to choose elements from it and put it in a .setText(). How do I this?
Example: XML file saved at res/values/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="planets_array">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
</string-array>
</resources>
This application code retrieves a string array:
String[] planets = getResources().getStringArray(R.array.planets_array);
Assigning the value to a textView:
TextView textView = (TextView) findViewById(R.id.textView1);
textView.setText(planets[1]); //Venus
Read more at:
http://developer.android.com/guide/topics/resources/string-resource.html
Should ArrayList be declared in arrays.xml?If so, use Context.getResource().getStringArray() to choose elements
Is there a way to extract a Spannable[] stuff from string resource? Basically something similar to
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="planets_array">
<item>Welcome to <b>Mercury</b></item>
<item>Welcome to <b>Venus</b></item>
<item>Welcome to <b>Earth</b></item>
<item>Welcome to <b>Mars</b></item>
</string-array>
</resources>
Then I would extract the array into
Resources res = getResources();
Spannable[] planets = res.getStringArray(R.array.planets_array);
But right now eclipse is telling me to change Spannable[] to String[].
use getTextArray, it returns CharSequence[] instead of String[] which preserves attached spans
I am trying to get the attribute "value" from my array in the xml file. This is my array:
<resources>
<string-array name="myArray">
<item name="item1" value="www.something.com" type="urls">first url</item>
<item name="item2" value="www.somethingelse.com" type="urls">second url</item>
</string-array>
</resources>
and basically I have a listview that should only display the name of the web page and in the intent, they will be redirected to the website. I am trying to get the value into a string.
Any help would be greatly appreciated.
Thankyou.
Based from your requirement, you can do it like this instead of reading the resource and read the file content manually/implementing the XML parser.
<resources>
<string-array name="array_url">
<item>www.something.com</item>
<item>www.somethingelse.com</item>
</string-array>
</resources>
<resources>
<string-array name="array_name">
<item>first url</item>
<item>second url</item>
</string-array>
</resources>
Then get the array with
String[] urls= getResources().getStringArray(R.array.array_url);
String[] names= getResources().getStringArray(R.array.array_name);
Use names for the list, and when it's clicked, you can get the item position, read the URL from urls.
Resources res = getResources();
String[] websites = res.getStringArray(R.array.myArray);
use this
String[] temp = getResources().getStringArray(R.array.myArray);
Try This...
String[] classes = getResources().getStringArray(R.array.myArray);
Im trying to set up a preferences but there is no options on the list here is the code
<ListPreference
android:title="list"
android:key="list"
android:summary= "This is a list to choose from"
android:entries="#array/list"
android:entryValues="#array/lvalues"
/>
Here is the code for the array
<string-array name="list">
<item Option="1"></item>
<item Option="2"></item>
<item Option="3"></item>
<item Option="4"></item>
</string-array>
<string-array name="lvalues">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>
I want it to say Option 1 etc next to the thing
Is this what you where trying to do?
<string-array name="list">
<item>Option 1</item>
<item>Option 2</item>
<item>Option 3</item>
<item>Option 4</item>
</string-array>
<string-array name="lvalues">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>
String Array
An array of strings that can be referenced from the application.
Note: A string array is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). As such, you can combine string array resources with other simple resources in the one XML file, under one <resources> element.
ELEMENTS
<string-array>
Defines an array of strings. Contains one or more elements.
attributes:
name
String. A name for the array. This name will be used as the resource ID to reference the array.
<item>
A string, which can include styling tags. The value can be a reference to another string resource. Must be a child of a <string-array> element. Beware that you must escape apostrophes and quotation marks.
No attributes.
This application code retrieves a string array:
Resources res = getResources();
String[] planets = res.getStringArray(R.array.planets_array);
Reference/Source:
http://developer.android.com/guide/topics/resources/string-resource.html#StringArray
I'm trying to about the Strings Resources of Android. I'm learning from the Android's developper guide
At the section String Array I'm trying the examples that they gives:
<?xml version="1.0" encoding="utf-8"?> <resources>
<string-array name="planets_array">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
</string-array> </resources>
in my .java I put this code:
...
Resources res = getResources();
String[] planets = res.getStringArray(R.array.planets_array);
I'm getting an error at the "array" in my .java file. Anyone has a clue?
Thanks!