Reputation: 49
I thought I had this figured out, but I obviously don't.
In an Android App I'm making a spinner will change it's contents based on a previous spinner's selection. The listener works and the second spinner is changing, however there is a third spinner that is not getting its contents.
What I would like to achieve is something along the lines of:
if (spinner1.selection == "Acura") {
spinner2 = "Acura";
}
The string-arrays that I'm calling are integers in the R.java
file so for Acura it would be: R.array.Acura
So my question would be:
How can I call the integer R.array.*
dynamically based on a string.
I hope my question makes sense.
Cheers
Upvotes: 1
Views: 161
Reputation: 37516
Use the getIdentifier() method on your activity to look up the resource ID.
For example:
spinner2 = "Acura";
int arrayResourceId = getResources().getIdentifier(spinner2, "array", getPackageName());
Upvotes: 2