Xml resource getStringArray (R. array. xxx) method, r. array

Source: Internet
Author: User

Xml resource getStringArray (R. array. xxx) method, r. array

Create menu_names.xml under res/values/

The Code is as follows:

<?xml version="1.0" encoding="utf-8"?><resources>     <string-array name="menu_names">        <item>xx1</item>                 <item>xx2</item>                 <item>xx3</item>              </string-array></resources>

In the onCreate (Bundle savedInstanceState) method:

String[] stringArray = getResources().getStringArray(R.array.menu_names);        menuList = new ArrayList<String>();        for (String str : stringArray) {            menuList.add(str);        }

Get the value in xml


What is the role of getContext () getResources () getStringArray () in Android?

GetResources (). getStringArray (R. array. setting); you can use this code to obtain the resources in the following xml file:
<Resources>
<String-array name = "setting">
<Item> View call details </item>
<Item> sending information </item>
<Item> Add to express dialing </item>
<Item> Delete </item>
<Item> Delete with the same number </item>
<Item> delete all call records </item>
<Item> Add to blacklist </item>
<Item> Delete blacklist </item>
</String-array>
<Resources>

GetStringArray (String key)

Inaccountinfo. java:
Intent intent = new Intent (Inaccountinfo. this, InfoManage. class); // create an Intent object
Intent. putExtra ("FLAG", new String [] {"strid", "strType"}); // pass data
StartActivity (intent); // execute the intent operation

InfoManage. java:
Intent intent = getIntent (); // get the Intent object
Bundle bundle = intent. getExtras (); // obtain the data of the transmitter and use the Bundle record
//!!!
Strinfos = bundle. getStringArray ("FLAG ");
For (int I = 0; I <strinfos. length; I ++ ){

System. out. println (strinfos [I]);
}

Change the program you wrote slightly. The output result is "strid" and "strType ". What do you want to express? I don't know. This is the result after the test. To solve this problem, you can test it on your own in eclipse. I guess you are just learning android. If so, we recommend that you do more. Check out developers.androidcn.com/reference/packages.html.

Related Article

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.