Skip to content Skip to sidebar Skip to footer

How To Reference A String-array Resource With A String That Is The Id?

Apologies for the terrible title, but couldn't think of a better one. So I have numerous string-array's in my strings.xml file. I want to be able to reference this by passing my in

Solution 1:

Not sure why you wanna do this, but you can pass the int ID directly:

Intent intent = newIntent(Main.this, Categories.class);
intent.putExtra("category", R.array.Categories); //R.array.Categories is an int valuestartActivity(intent); 

Then..

int myArrayID = bundle.getIntExtra("category", 0); 
myArray = getResources().getStringArray(myArrayID)));

Solution 2:

Solution 3:

Not much of an answer, but that is correct: see getStringArray. You will want to cast it correctly, but otherwise you got it right.

Post a Comment for "How To Reference A String-array Resource With A String That Is The Id?"