Android xml檔案裡讀取string array

來源:互聯網
上載者: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 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 );

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.