6

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>
0

3 Answers 3

9

Well I will use the second approch, if you need to localize (translate it in more languages) your strings.

Sign up to request clarification or add additional context in comments.

Comments

2

The second solution is better, because you can use different languages later (english, german etc.) http://developer.android.com/guide/topics/resources/localization.html

Comments

0

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.

2 Comments

but remember to change it in each language or you might get errors
but even if it is just change in XML file, still we have to generate the apk right ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.