【问题标题】:Drawable Images in SQLite androidSQLite android中的可绘制图像
【发布时间】:2012-07-12 19:28:49
【问题描述】:

我有一个使用数据库填充文本的工作 TextView,但我想连接本地数据库中的图像路径名称。这怎么能在java中合并?

在我设置的主要活动中:

String image = currentQ.getImage();
ImageView iView = (ImageView) findViewById(R.id.IS);
Bitmap bMap = BitmapFactory.decodeFile(image);
iView.setImageBitmap(bMap);

在问题中:

private String image;

/**
* @return the image
*/
public String getImage() {
return image;
}
/**
 * @param image the image to set
 */
public void setImage(String image) {
this.image = image;
}

在数据库中,我将其声明为文本:

file.path.name/drawable/i1.jpg and so on for the others.

如何在我的可绘制文件夹中为数据库中的每个问题附加一个图像文件位置并在 java 中连接它?

提前致谢。

【问题讨论】:

  • 你不能,你drawables文件夹中的图像只能通过那里的id来引用,即R.drawable.imageName。如果你想要一个静态路径,你需要做一些不同的事情,即将它们放在资产文件夹中,然后提取它们或作为原始资产。
  • 如何做到这一点?关于我将路径放入数据库的想法 - 即当我选择一个答案时,它会移动到下一个问题,并且图像会附加到呈现的文本中??
  • 我们在谈论多少张图片?
  • 加载 :D 100+ 那是我的障碍 - thanx

标签: android database image sqlite drawable


【解决方案1】:
ImageView imageView = (ImageView) findViewById(R.id.imageView);

String imageName = "NameofImage"; // store only image name in database(means not   store "R.drawable.image") like "image".
            int id = getResources().getIdentifier("projectPackageName:drawable/" + imageName, null, null);
            imageView.setImageResource(id);

【讨论】:

  • 请解释你的答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多