[英]How to get the image from drawable folder in android?
I am working on quiz application. 我正在研究测验应用程序。 I stored the column data in the following form in sqlite database.
我将列数据以以下形式存储在sqlite数据库中。
I am able to retrieve the question but now I need to retrieve the image of that particular question. 我可以检索问题,但是现在我需要检索该特定问题的图像。 I kept the images in drawable folder.
我将图像保存在可绘制的文件夹中。 But I need to change the
ie src="/test/image1.png" to src="/drawable/image1.png"
. 但是我需要将
ie src="/test/image1.png" to src="/drawable/image1.png"
。 If I change the path like the path of the image in sqlite colum at then can I get the image which I kept in my drawable folder? 如果我像在sqlite colum中更改图像路径一样更改路径,那么能否获得保存在可绘制文件夹中的图像? Please help me regarding this...
请帮我...
Thanks in advance 提前致谢
I would insist that in database you can just give the name of the image and then you can get the image using getIdentifier
, 我会坚持认为,在数据库中,您只需给出图像的名称,然后可以使用
getIdentifier
获得图像,
getResources().getIdentifier(name,"drawable", getPackageName());
Where name will be the name of your image ie - "image1"
名称将是您的图像的名称,即-
"image1"
It can be done like this aswell: 也可以这样完成:
Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
where this refers to the context of the actual activity. 这里指的是实际活动的上下文。
getResources()。getIdentifier(name,“ drawable”,getPackageName());
只需命名src =“ image1.png”并将文件放在资产文件夹图像和html中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.