分享

Android xml文件里读取string array

 black library 2011-10-30
 

Android xml文件里读取string array

分类: android 83人阅读 评论(0) 收藏 举报
 

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

 

 

http://blog.csdn.net/ancestors/article/details/6462166

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多