0

Starting from this method:

weatherIconView.setIconResource(getString(R.string.wi_day_sunny));

I would like to use the iconID receiver from an API to call the specific string from the string.xml file:

 <string name="wi_00d">&#xf00d;</string>

Now, I cannot name the string starting with a number, and the API provides all the iconID's starting with a number. So I tried concatenating "wi_" to the iconID's string, but when I tryed to call the method using that:

iconName = "wi_" + iconId;
weatherIconView.setIconResource(getString(R.string.iconName));

It just does not work (pretty sure I am approaching this the wrong way. Is there a correct way to do this? Or should I try something else?

  • 1
    If you want to stick with that, you can use the `Resources#getIdentifier()` method to get the `int` value to replace the `R.string.whatever` that you would normally use in the `getString()` call. There's a decent example in [this answer](https://stackoverflow.com/a/11595723). – Mike M. Jul 31 '21 at 15:38

0 Answers0