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]);
        }

}
2
  • possible duplicate of Dynamically build a resource Identifier Commented Aug 7, 2014 at 17:54
  • Solved with that article. Sorry for duplicating. Commented Aug 7, 2014 at 19:32

2 Answers 2

1

This should be working:

int[]myArray = getResources().getIntArray(R.array.myArrayInXML);
Sign up to request clarification or add additional context in comments.

Comments

0
Try

 int[] arrayAdy=getResources().getIntArray(getResources().getIdentifier("p100", "array", getPackageName()));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.