i need to show images from sqlite database into gridview or gallery view.
this is the code for displaying on a single view:
mMain = (ImageView) findViewById(R.id.ivMain);
byte[] blob = imgs.getBytes(); //there is a method that will return the bytes from the database
ByteArrayInputStream inputStream = new ByteArrayInputStream(blob);
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
mMain.setImageBitmap(bitmap);
i have the android tutorial for grid view but it gets the image from file
// references to our images
private Integer[] mThumbIds = {
R.drawable.sample_2, R.drawable.sample_3
... }
is there a way to populate the gridview from the sqlite database?
UPDATE:
Im using the ImageAdapter provide in android tutorial:
http://developer.android.com/resources/tutorials/views/hello-gridview.html
my code becomes this:
ArrayList<byte[]> image_arr = new ArrayList<byte[]>();
//loop through all images on sqlite
for(int l = 0 ;l< db.getAllImages().size(); l++){
Image imgs = db.getAllImages().get(l);
byte[] blob = imgs.getBytes();
image_arr.add(blob);
ByteArrayInputStream inputStream = new ByteArrayInputStream(blob);
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
// mMain.setImageBitmap(bitmap);
}
//TODO; find way to make the bitmap get to the ImageView
Gallery gallery = (Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new ImageAdapter(this));
This code is on main activity so i need to find way to pass the resources in ImageView which is in other file.
1 Answer