I'm having a problem using strings stored in my strings.xml
, I have a wide list of strings stored there. They are very useful for me because I'm using them to translate my program. However, now I want to choose between those strings dynamically and I don't know how to do it. It will be easier to understand with an example. Let's assume that I have the following strings:
<string name="red">Red</string>
<string name="blue">Blue</string>
<string name="green">Green</string>
<string name="yellow">Yellow</string>
And now let's assume that I have a function that passes me a string with a color, for example "yellow"
. Now I only have a solution for this, to make a very huge switch (very very huge, because I have lots of strings), I think that there must be an option to transform the output of my function into the right parameter.
I mean, if I have a function that returns me "yellow"
, and I want to use R.strings.yellow
, there must be a link between them. I don't know if maybe you could use any kind of reflection to achieve this.
Can you help me?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…