嘿,我得到這個XML數組:塞汀使用color.xml顏色 - 一個字符串數組
<resources>
<string-array name="colors">
<item>BLUE</item>
<item>CYAN</item>
<item>DARK_GRAY</item>
<item>GRAY</item>
<item>GREEN</item>
<item>LIGHT_GRAY</item>
<item>MAGENTA</item>
<item>ORANGE</item>
<item>PINK</item>
<item>RED</item>
<item>YELLOW</item>
<item>WHITE</item>
</string-array>
</resources>
我試圖這樣簡單的方法,這顯然不能工作:
public int[] getColorsArray(int i) {
int[] allColors = MyApplication.getContext().getResources().getIntArray(R.array.colors); //this is probably wrong
int[] array = new int[i];
for (int j = 0; j < array.length; j++) {
array[j] = allColors[j]; //this is wrong
}
return array;
}
}
有沒有辦法使用這樣的XML數組?
你想完成什麼? – jagsler 2011-12-30 13:01:35
實際上,我需要一個圖表系列的顏色數組。我想從allColors數組中挑選必要的顏色。 – 2011-12-30 13:05:13
好的,有什麼錯誤? – jagsler 2011-12-30 13:09:25