0

I want to get the separate arrays from an xml file. The thing is, i need to get those arrays depending on variable i value.

For example: First get R.array.p100, then R.array.p101 ...

(int i=100;i<=106;i++)
{
        listaAdy= new ArrayList<Integer>();
        listaOpc = new ArrayList<Integer>();

        String pActual = "r.array.p"+i; // this should get "R.array.p100" but i can't make it work as a parameter.

        int[] arrayAdy = r.getIntArray(pActual);

        for(int j=0;j<arrayAdy.length;j++)
        {
            listaAdy.add(arrayAdy[j]);
        }

}
joran
  • 169,992
  • 32
  • 429
  • 468

2 Answers2

1

This should be working:

int[]myArray = getResources().getIntArray(R.array.myArrayInXML);
Lal
  • 14,726
  • 4
  • 45
  • 70
cheko506
  • 358
  • 1
  • 11
0
Try

 int[] arrayAdy=getResources().getIntArray(getResources().getIdentifier("p100", "array", getPackageName()));
Rajnish Mishra
  • 826
  • 5
  • 21