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

发布于 2024-10-21 04:29:44 字数 1023 浏览 1 评论 0原文

这可能非常简单,但目前我一无所获。 我已经阅读了很多帖子,但还没有找到答案。 我的应用程序中有一个画廊,主要基于谷歌画廊应用程序,图像存储在 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”类中,我尝试将数组复制到“整数”数组 mImageIds 中:

public class ImageAdapter extends BaseAdapter {
    int mGalleryItemBackground;

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

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

This is probably pretty straight forward, but I am getting no-where at the moment.
I have read through a lot of posts but have not hit the answer yet.
I have a gallery in my app,based largely on the google gallery app, with the images stored in R.drawable and the paths to the images stored in an 'Integer' array.
I have moved the image paths into a database table and am trying to read them back and so display the images, but all I am seeing is a blank gallery.
I would be so grateful if someone could point me in the right diorection here, I feel I'm going in circles.
Below is the code I use to read the items from the database:

//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();

This is the Integer array the names paths are read into:

private Integer[] myImageIds;

Then in the 'ImageAdapter' class I try to copy the array into the 'Integer' array mImageIds:

public class ImageAdapter extends BaseAdapter {
    int mGalleryItemBackground;

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

As I say, this gives me an empty gallery, where am I going wrong?
Is there a different way to store the paths to the drawable directory in a database?
Any help appreciated.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

说好的呢 2024-10-28 04:29:44

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

The path to your images isn't truly an integer. It's just referenced in that way in the R class. I guess I said that pretty definitively, but what I'm really offering is a hint/clue based on what I believe to be true. It's like R.strings.myString ... that's an "integer" too though it's just an integer reference to a string. Make sense?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文