1

我正在开发测验应用程序。我将列数据以下列形式存储在 sqlite 数据库中。 在此处输入图像描述

我能够检索问题,但现在我需要检索该特定问题的图像。我将图像保存在可绘制文件夹中。但我需要更改i.e src="/test/image1.png" to src="/drawable/image1.png". 如果我像在 sqlite 列中的图像路径一样更改路径,那么我可以获得保存在可绘制文件夹中的图像吗?请帮我解决这个问题...

提前致谢

4

4 回答 4

8

我会坚持在数据库中你可以只给出图像的名称,然后你可以使用获取图像getIdentifier

getResources().getIdentifier(name,"drawable", getPackageName());

其中 name 将是您的图像的名称,即 -"image1"

于 2012-05-21T10:27:42.493 回答
5

也可以这样做:

 Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);

这里指的是实际活动的上下文。

于 2012-05-21T10:49:48.973 回答
2

getResources().getIdentifier(name,"drawable", getPackageName());

于 2012-05-21T10:36:58.077 回答
0

只需命名 src="image1.png" 并将文件放入您的资产文件夹图像和 html

于 2012-05-21T11:06:01.493 回答