Android xml文件里读取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.

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 of 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:

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 referenced to another string resource. Must be a child of a <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 );

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值