:)
Im using Java in Android Studio and trying to access a resource file (/res/values/nutrients.xml).
In the nutrients.xml, there are multiple integer-arrays (nut1, nut2, nut3...) :
I have already managed to access the data with this code:
Resources r = ctx.getResources();
int[] food = r.getIntArray(R.array.nut1);
return food[1];
Now i want to do this dynamically, changing the array (before nut1) depending on an integer. I will be providing an integer for that function, that specifies which array im looking for.
I thought that I could just do something like this:
public int getNutrientInfo(int foodNo, int nutType){
Resources r = ctx.getResources();
String arrayName = "R.array.nut" + foodNo;
int[] testy = r.getIntArray(arrayName);
return testy[nutType];}
That does not work. I have tried multiple things but can´t find a solution. I am quite sure it is fairly easy though.
Do you have a solution?
Thank you for your help :)