使用setImageDrawable动态地设置的图像在ImageView的 [英] Using setImageDrawable dynamically to set image in an ImageView

查看:2427
本文介绍了使用setImageDrawable动态地设置的图像在ImageView的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成动态地从数据库中一个字符串,它具有图像的同名绘制文件夹中。

I am generating a string from database dynamically which has the same name of image in drawable folder.

现在我想要设置值的ImageView 使用 setImageDrawable(R.id.StringGenerated)动态。

Now I want to set that value for ImageView using setImageDrawable(R.id.StringGenerated) dynamically.

任何建议..

推荐答案

试试这个,

int id = getResources().getIdentifier("yourpackagename:drawable/" + StringGenerated, null, null);

这将返回您要访问的绘的ID ...
那么你可以通过执行以下操作设置在ImageView的图像

This will return the id of the drawable you want to access... then you can set the image in the imageview by doing the following

imageview.setImageResource(id);

这篇关于使用setImageDrawable动态地设置的图像在ImageView的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆