I have a Spinner
on my Activity
with items "hello" and "goodbye" for user to choose. These items, when device is in Spanish, would be "hola" and "adios", as strings are chosen from string-es/
instead from string
.
The problem is that I've got many switch cases on my code like this:
switch(spinnerSelectedItem){
case "hello":
case "hola":
//do something
break;
case "goodbye":
case "adios":
//do something else
break;
}
I've tried to create a final String initialized with string resource, but it complains saying "Constant Expression Required"
final String resHello = getResources().getString(R.string.helloText);
final String resGoodbye = getResources().getString(R.string.goodbyeText);
switch(spinnerSelectedItem){
case resHello :
//do something
break;
case resGoodbye :
//do something else
break;
}
This is a simplified version, I have many more items and more than two languages
One solution would be to use strings id instead of value, or use if clauses instead of switch, but I would like to find a "smart" or "clean" way to do this, do you have any idea?