Android Reading image names from database
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 =开发者_JAVA百科 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
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?
精彩评论