Reputation: 65
What is better to use in my android program:
in mainActivity.java:
String[] st = {"Value1","Value2"};
or
in mainActivity.java:
String[] st = (String[]) getResources().getStringArray(R.array.Array1);
And in strings.xml:
<string-array name="Array1">
<item >Value1</item>
<item >Value2</item>
</string-array>
Upvotes: 6
Views: 5120
Reputation: 19502
I will also suggest to use the 2nd one as others suggested. Additionally it also helps you, if in case you want to change the elements of the array or if you want to add/delete elements of the array. In this case you don't need to change the source code again and recompile it. Instead you just need to change the XML file only and its done.
Upvotes: 0
Reputation: 157457
Well I will use the second approch, if you need to localize
(translate it in more languages) your strings.
Upvotes: 9
Reputation: 4117
The second solution is better, because you can use different languages later (english, german etc.) http://developer.android.com/guide/topics/resources/localization.html
Upvotes: 2