Reputation: 53
I'm trying to make an arraylist so then I can randomly pick a string from a list. I visited this question and on this question there was the perfect answer for what I wanted to do. Although on this piece of code:
String[] colorsTxt = getApplicationContext().getResources().getStringArray(R.array.colors);
List<Integer> colors = new ArrayList<Integer>();
for (int i = 0; i < colorsTxt.length; i++) {
int newColor = Color.parseColor(colorsTxt[i]);
colors.add(newColor);
}
I can't find why getApplicationContext gives me an error, someone has an idea?
Thanks
Upvotes: 1
Views: 167
Reputation: 1299
Because you said you are using it in a fragment, you need to call getActivity().getResources()...
to access it :).
Upvotes: 3