是否可以通过编程方式添加图像?
我有一个网络服务,我可以从中读取各种信息。这些信息之一是图像的名称。我将所有图像存储在本地的可绘制文件夹中。我现在所做的是从网络服务中读取我需要的图像字符串。我想使用这个字符串名称并从我的可绘制文件夹中插入具有相同字符串名称的图像。这可以吗?
是否可以以某种方式执行以下操作?
//Setup the image
ImageView spotIvIcon = (ImageView)findViewById(R.id.spot_selected_image);
String temp = "R.drawable."+spotImage;
spotIvIcon.setImageResource(R.drawable.beer);
我对临时字符串做了什么。是否可以将这个字符串转换为我需要的int?我那里有啤酒只是为了测试一下。 谢谢
I have a web service where I read various information from. One of these pieces of information is the name of an image. I have all the images stored locally in the drawables folder. What I have done right now is I read the string of the image I need from the web service. I want to use this string name and insert the image with the same string name from my drawable folder. Is this possible to do?
Is it possible to do the following somehow?
//Setup the image
ImageView spotIvIcon = (ImageView)findViewById(R.id.spot_selected_image);
String temp = "R.drawable."+spotImage;
spotIvIcon.setImageResource(R.drawable.beer);
What I do with the temp string. Is it possible to convert this string into the int I need? I have the beer in there just to test something out.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以我找到了如何做到这一点。如果有人想知道它是如何完成的,请使用以下代码:
其中:
,现在就像魅力一样。
So I found out how to do this. If anyone wanted to know how it's done use the following code:
Where:
Works like a charm now.
您可以使用 asset 目录来存储这些图像,然后使用 BitmapFactory.decodeStream(assetManager.open(imAnAssetName)); 之类的方法加载它们;
asset 目录,它用于处理您不想由资源管理器管理(或无法管理)的内容。
http://developer.android.com/reference/android/content/res /AssetManager.html 。
you could just use the assets directory to store these images, and then load them using something like BitmapFactory.decodeStream(assetManager.open(imAnAssetName));
the asset directory it's here to be used for things you don't want to be managed (or that can't be managed) by the resource manager.
http://developer.android.com/reference/android/content/res/AssetManager.html .