0

i want to get array from myapp.R.array.*. means if i have this array.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string-array name ="processName">
        <item >solve</item>
        <item >simplify</item>
        <item >plot</item>
        <item ></item>
    </string-array>

</resources>

then i must have in variable : ["solve","simplify","plot","",]

1

1 Answer 1

3

Taking from @Raghunandan's comment, you can use the getStringArray() method.

http://developer.android.com/guide/topics/resources/string-resource.html

String[] processNames = getResources().getStringArray(R.array.processName);

You can then traverse the array as normal, or put it into an adapter if you are trying to display the options in a spinner or list view.

Be sure to note that you need a context in order to use this method. So, if you are not inside of an Activity, you'll need to use a passed reference to a context.

String[] processNames = context.getResources().getStringArray(R.array.processName);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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