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?
private void getDataAndPopulate() {
ReplyDeleteimage = new ArrayList<byte[]>();
caption = new ArrayList<String>();
cursor=db.rawQuery("select * from NAME",null);
while (cursor.moveToNext()) {
byte[] temp_image = cursor.getBlob(2);
String temp_caption = cursor.getString(1);
String temp_id= cursor.getString(0);
image.add(temp_image);
caption.add(temp_caption);
id.add(temp_id);
}
String[] captionArray = (String[]) caption.toArray(
new String[caption.size()]);
ItemsAdapter itemsAdapter = new ItemsAdapter(Item_show_grid.this, R.layout.item_grid,captionArray);
gv.setAdapter(itemsAdapter);
}