Reading String Array in Android XML file

Source: Internet
Author: User

 

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 );

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.