Android uses an array resource in an XML file

Source: Internet
Author: User
Tags tag name

There's a very simple use of arrays in Android that gets in an XML file.

Creating an array Resource

Create a Arrays.xml file under the value directory

Then use the <string-array> or <integer-array> tags in the arrays.xml file to define the array:

<?xml version= "1.0" encoding= "Utf-8"?><resources> <string-array    name= "Languages" >        < Item>c language </item>        <item>java </item>        <item>C#</item>        <item>php </item>        <item>HTML</item>    </string-array>      <integer-array name= "Reminder_ Methods_values "translatable=" false ">        <item>1</item>           <item>2</item>          <item>3</item>      </integer-array> </resources>
Referencing array resources: Referencing in Java code
Resources res == = Res.getintarray (r.array.reminder_methods_values);
Referencing in XML

Take the spinner control as an example, because the entries property of spinner just needs to be an array resource

<Spinner    android:id= "@+id/spinner1"    android:layout_width= "Match_parent"     Android:layout_height= "Wrap_content"    android:entries= "@array/languages"  />

Note that the reference above is @array.

In fact, the array resources are not necessarily defined in the Values/arrays.xml file, this is an unwritten convention, the above <string-array name= "languages" > The definition is also possible in Strings.xml.

Android system for all XML resource files is actually no different, think that the values of the resource type is not put in what file, but in the name of the tag, such as the String-array tag name determines that this is an array resource.

It is recommended that array resources be uniformly placed in values/arrays.xml.

Android uses an array resource in an XML file

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.