Advertisement
DRK

string array in Android

DRK
Aug 27th, 2011
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. I need to access stringarray present in res/values/string.xml to Activity class. Below shown is my code
  2.  
  3. package com.string;
  4.  
  5. import android.app.Activity;
  6. import android.os.Bundle;
  7.  
  8. public class FirstAct extends Activity {
  9. /** Called when the activity is first created. */
  10. @Override
  11. public void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.main);
  14. String arr[] = getResources().getStringArray(R.array.planet);
  15. for (int i = 0; i < arr.length; i++) {
  16. System.out.println(arr[i]);
  17. }
  18. }
  19. }
  20.  
  21.  
  22.  
  23.  
  24. string.xml
  25.  
  26.  
  27. <?xml version="1.0" encoding="utf-8"?>
  28. <resources>
  29. <string name="hello">Hello World, FirstAct!</string>
  30. <string name="app_name">string</string>
  31. <string-array name="planet">
  32. <item>Mercury</item>
  33. <item>Venus</item>
  34. <item>Earth</item>
  35. </string-array>
  36. </resources>
  37.  
  38.  
  39. This is LogCat
  40.  
  41. 08-28 08:16:59.166: DEBUG/AndroidRuntime(346): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
  42. 08-28 08:16:59.166: DEBUG/AndroidRuntime(346): CheckJNI is ON
  43. 08-28 08:16:59.306: DEBUG/AndroidRuntime(346): --- registering native functions ---
  44. 08-28 08:16:59.896: DEBUG/AndroidRuntime(346): Shutting down VM
  45. 08-28 08:16:59.896: DEBUG/dalvikvm(346): Debugger has detached; object registry had 1 entries
  46. 08-28 08:16:59.926: INFO/AndroidRuntime(346): NOTE: attach of thread 'Binder Thread #3' failed
  47. 08-28 08:17:00.426: DEBUG/AndroidRuntime(354): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
  48. 08-28 08:17:00.426: DEBUG/AndroidRuntime(354): CheckJNI is ON
  49. 08-28 08:17:00.566: DEBUG/AndroidRuntime(354): --- registering native functions ---
  50. 08-28 08:17:01.166: INFO/ActivityManager(58): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.string/.FirstAct }
  51. 08-28 08:17:01.166: DEBUG/AndroidRuntime(354): Shutting down VM
  52. 08-28 08:17:01.176: DEBUG/dalvikvm(354): Debugger has detached; object registry had 1 entries
  53. 08-28 08:17:01.196: INFO/AndroidRuntime(354): NOTE: attach of thread 'Binder Thread #3' failed
  54. 08-28 08:21:23.466: DEBUG/SntpClient(58): request time failed: java.net.SocketException: Address family not supported by protocol
  55.  
  56.  
  57. This is console
  58.  
  59. [2011-08-28 08:16:59 - string] ------------------------------
  60. [2011-08-28 08:16:59 - string] Android Launch!
  61. [2011-08-28 08:16:59 - string] adb is running normally.
  62. [2011-08-28 08:16:59 - string] Performing com.string.FirstAct activity launch
  63. [2011-08-28 08:16:59 - string] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'rr'
  64. [2011-08-28 08:17:00 - string] Application already deployed. No need to reinstall.
  65. [2011-08-28 08:17:00 - string] Starting activity com.string.FirstAct on device emulator-5554
  66. [2011-08-28 08:17:02 - string] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.string/.FirstAct }
  67. [2011-08-28 08:17:02 - string] ActivityManager: Warning: Activity not started, its current task has been brought to the front
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement