1

I'm developing an application that intends to store the data in a SQLIte database. It's kind of a virtual city guide.
As so, I'm storing some text elements on the DB and I'd like to store the path of an image and a video stored in the device in different columns and tables of the DB.

Kind of:

_ID INTEGER PRIMARY KEY AUTOINCREMENT (id of the image)
IMAGE_PATH TEXT UNIQUE (path of the image associated with the ID)

Can anyone give some examples on how can I do this?

1
  • 1
    What have you tried? Showing an attempt at some code, or doing searches for examples shows that you've done you're homework Commented Mar 25, 2012 at 22:56

2 Answers 2

2

The answer of Bill Gary works well for one image, but as I want to do a gallery I used the code below :

this.imgPath = new String[mImageCursor.getCount()];

        int i = 0;

        while (mImageCursor.moveToNext()) {
            imgName = mImageCursor.getString(mImageCursor.getColumnIndex(MyDbAdapter.IMAGE_PATH));
            Log.w(TAG, baseDir + imgName);
            this.imgPath[i] = baseDir + imgName;
            Log.w(TAG, baseDir + mImageCursor.getString(mImageCursor.getColumnIndex(MyDbAdapter.IMAGE_PATH)) + " After");
            i++;
        }

        Gallery gallery = (Gallery) findViewById(R.id.VGgallery);
        gallery.setAdapter(new MyImageAdapter(this, this.imgPath));

Hope it helps someone else.

Sign up to request clarification or add additional context in comments.

Comments

0

Store the path as text, tehn when you get it in your cursor(variable imagePath for example), use this ...

imageResource = this.getResources().getIdentifier(
                imagePath, null, null);
ImageView.setImageResource(imageResource);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.