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
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.
File Location: Res/values/Filename. Xml
The filename is arbitrary. The <string-array> element's
Name will be used as the resource ID. compiled resource datatype: Resource pointer to an array
String
S. resource reference: in Java: R. array.String_array_name
Syntax: <? XML version = "1.0"
Encoding = "UTF-8"?>
<
Resources>
<
String-array
Name ="String_array_name
">
<
Item
>Text_string</Item>
</String-array>
</Resources> elements: <resources>
Required.This must be the root node.
No attributes.
<String-array> defines an array of strings. contains one or more
<Item> elements.
Attributes:
NameString. 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 referenced to another string resource. Must be a child of
<String-array> element. Beware that you must escape apostrophes and quotation marks. See
Formatting and styling, below, for information about to properly style and format your strings.
No attributes.
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:
Resources res =
Getresources ();
String [] planets =
Res.
Getstringarray (R.
Array. planets_array );