我在可拉的文件夹中存储了程序中的相关图像,同时在字符串变量中存储了图像名称。然后在imageview 中使用代码设置这些图像。但是结果图像不显示。
代码如下:
int res = getResources().getIdentifier(imagename, "drawable", this.getPackageName());
imageview= (ImageView)findViewById(R.id.imageView);
imageview.setImageResource(res);
上面代码中 "imagename" 是在字符串变量,包含图像名。
imagename是不带后缀名的