0

I've got a string-array

<string-array name="color">
    <item>red</item>
    <item>green</item>
    <item>purple</item>
</string-array>
  1. How could I get it's name with Java? (I want to get a string with "color" inside)

  2. How to I extract it's name to a string? To do smth like this:

     <string-array name="@string/color">
         <item>red</item>
         <item>green</item>
         <item>purple</item>
     </string-array>
    

<string name="color">color</string>

  1. Is it redudant to extract all items of a string-array to strings? like this:

     <string-array name="color">
     <item>@string/red</item>
     <item>@string/green</item>
     <item>@string/purple</item>
    

<string name="red">red</string> <string name="green">green</string> <string name="purple">purple</string>

2 Answers 2

2
  1. From the documentation:

    Resources res = getResources(); String[] colors = res.getStringArray(R.array.color);

  2. As far as I know, you can not do this.

  3. It depends on how you want to use the array. For example, if you have more than one language in your app, it makes sense to give the item a value that is a reference to another string resource .

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

1 Comment

Are you sure about the second one?
0
  1. getResources().getResourceEntryName(R.array.variant);
  1. I can't translate strings without extracting them like so.

Comments

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.