-1

I want to do something similar to this as explained in Reference drawable from string-array in android

private Integer[] mThumbIds = {
        R.drawable.sample_2, R.drawable.sample_3,
        R.drawable.sample_4, R.drawable.sample_5,
        R.drawable.sample_6, R.drawable.sample_7,
        R.drawable.sample_0, R.drawable.sample_1,
        R.drawable.sample_2, R.drawable.sample_3,
        R.drawable.sample_4, R.drawable.sample_5,
        R.drawable.sample_6, R.drawable.sample_7,
        R.drawable.sample_0, R.drawable.sample_1,
        R.drawable.sample_2, R.drawable.sample_3,
        R.drawable.sample_4, R.drawable.sample_5,
        R.drawable.sample_6, R.drawable.sample_7
};

I tried this .java file :

    int[] descriptions = new int[] { 
        R.string.description_section1, 
        R.string.description_section2, 

    }; 

but it doesn't seem to be the right syntax.

Community
  • 1
  • 1
user310291
  • 36,946
  • 82
  • 271
  • 487

2 Answers2

2

Try this as mentioned in the docs:

int[] descriptions = { 
    R.string.description_section1, 
    R.string.description_section2, 

}; 
Steve Benett
  • 12,843
  • 7
  • 59
  • 79
  • @BobMalooga Because this compiles just fine, I think the extra comma at the last element is optional. But I don't know where this is specified. – Steve Benett Apr 27 '14 at 09:24
2

define your array in array.xml:

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

    <string-array name="descriptions">
        <item>section1</item>
        <item>section1</item>
    </string-array>
 </resources>

then try this:

String[] descriptions = getResources().getStringArray(
                R.array.descriptions);
Chaoba
  • 21
  • 2