[ACCEPTED]-Get an integer array from an xml resource in Android program-android

Accepted answer
Score: 69

You need to use Resources to get the int 9 array; however you're using the system resources, which 8 only includes the standard Android resources 7 (e.g., those accessible via android.R.array.*). To get your 6 own resources, you need to access the Resources 5 via one of your Contexts.

For example, all 4 Activities are Contexts, so in an Activity 3 you can do this:

Resources r = getResources();
int[] bases = r.getIntArray(R.array.UserBases);

This is why it's often useful 2 to pass around Context; you'll need it to 1 get a hold of your application's Resources.

More Related questions