Normally, I use
String[] arrayName = getResources().getStringArray(R.array.name_array);
So are there any ways to use
String[] arrayName = getResources().getStringArray(R.array.NAME);
with NAME is string (String NAME = "name_array";
)?
Going by what is in the official documentation, this is an acceptable way of referencing your array. However, I need to point out an error in your flow:
name_array
.You can do the referencing this way:
int NAME = R.array.name_array; // use a variable to store the int reference
String[] arrayName = getResources().getStringArray(NAME); //fetch
Android replace string name to integer id after compile, but you place id to varialbe