Use of array Resources

Source: Internet
Author: User
Step: 1. Create the arrays. xml file under res/values. The content is as follows: <? Xml version = "1.0" encoding = "UTF-8"?> <Resources> <string-array name = "testStringArray"> <item> hello1 </item> <item> hello2 </item> <item> hello3 </item> <item> hello4 </item> </string-array> <integer-array name = "testIntegerArray"> <item> 1 </item> <item> 2 </item> <item> 3 </item> <item> 4 </item> </integer-array> </resources> 2. Call resources in MainActivity and traverse the array, the content is as follows: package cn.com. bravesoft; import android. app. activity; import android. OS. bundle; public class TestArray extends Activity {@ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); // obtain the array String stringsArray [] = this. getResources (). getStringArray (R. array. testStringArray); int ingegersArray [] = this. getResources (). getIntArray (R. array. testIntegerArray); // traverses the array for (int I = 0; I <stringsArray. length; I ++) {System. out. println ("XXXXX stringsArray [I] =" + stringsArray [I]);} for (int I = 0; I <ingegersArray. length; I ++) {System. out. println ("XXXXX ingegersArray [I] =" + ingegersArray [I]) ;}}

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.