如何解决设置可绘制的字符串值
我该如何替换
Drawable drawable = getResources().getDrawable(R.drawable.imagesample);
具有String img的值吗? (“字符串img的值是可绘制的图像名称”)
我的代码:
String img = "sampleimage";
// code for image in pop-up dialog
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
View subView = inflater.inflate(R.layout.dialog,null);
final ImageView subImageView = (ImageView) subView.findViewById(R.id.image);
Drawable drawable = getResources().getDrawable(R.drawable.imagesample);
subImageView.setImageDrawable(drawable);
// code for a pop-up dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Congratulations");
builder.setMessage("Thanks for helping me!");
builder.setView(subView);
builder.setPositiveButton("Ok",null);
builder.show();
解决方法
不可能。您试图做的事根本不可能。
getDrawable
方法接受一个int
参数。您正在尝试通过string
。您不能调用参数类型错误的方法。
检查https://developer.android.com/reference/android/content/res/Resources以获得更多参考。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。