Android从数据库中读取图像名称

时间:2011-03-10 19:17:19

标签: android sqlite

这可能很直接,但我现在没有在哪里。 我已阅读了很多帖子,但尚未找到答案。 我的应用程序中有一个库,主要基于谷歌库应用程序,图像存储在R.drawable中,图像的路径存储在“整数”数组中。 我已将图像路径移动到数据库表中,并尝试将其读回并显示图像,但我所看到的只是一个空白的图库。 如果有人能指出我在这里正确的解决方案,我会感激不尽,我觉得我是在圈子里。 下面是我用来从数据库中读取项目的代码:

//get the gallery items from the cursor
    ArrayList galleryList = new ArrayList();
    for(cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext()){
        Integer gal;
        gal = cursor.getInt(cursor.getColumnIndex("small_img"));
        galleryList.add(gal);
    }
    myImageIds =(Integer[])galleryList.toArray(new Integer[galleryList.size()]);
    db.close();

这是读取名称路径的整数数组:

private Integer[] myImageIds;

然后在'ImageAdapter'类中我尝试将数组复制到'Integer'数组mImageIds:

public class ImageAdapter extends BaseAdapter {
    int mGalleryItemBackground;

    public ImageAdapter(Context c) {
        mContext = c;
        mImageIds = Drager.this.myImageIds;

正如我所说,这给了我一个空的画廊,我哪里错了? 是否有不同的方法将路径存储到数据库中的drawable目录? 任何帮助赞赏。 感谢

1 个答案:

答案 0 :(得分:0)

图像的路径不是真正的整数。它只是在R类中以这种方式引用。我想我说得非常明确,但我真正提供的是基于我认为是真实的提示/线索。它就像R.strings.myString ......虽然它只是对字符串的整数引用,但它也是一个“整数”。有意义吗?

相关问题