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.