首页 > 解决方案 > Android:使用字符串 ID 调用字符串资源

问题描述

从这个方法开始:

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

我想使用 API 中的 iconID 接收器来调用 string.xml 文件中的特定字符串:

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

现在,我无法命名以数字开头的字符串,API 提供了所有以数字开头的 iconID。所以我尝试将“wi_”连接到 iconID 的字符串,但是当我尝试使用它调用该方法时:

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

它只是不起作用(很确定我以错误的方式接近这个。有正确的方法吗?或者我应该尝试其他方法吗?

标签: stringandroid-studioopenweathermap

解决方案


推荐阅读