我有一个imageView,想在其中显示当前所在国家的小图标。我可以获取国家代码,但问题是我无法动态更改imageView的资源。我的图像文件全部为小写(例如:国家代码=US,则图像文件=us)。
我的代码(countryCode是当前大写字母的国家代码):
String lowerCountryCode = countryCode.toLowerCase();
String resource = "R.drawable." + lowerCountryCode;
img.setImageResource(resource);
当然,这样做是行不通的,因为setImageResource
需要一个int
参数,那么我该怎么做呢?