0

I have Database, where I have 3 columns (first Id,second title String, third image int). DB like contact list with photo.

ContentValues cv = new ContentValues();
cv.put(COLUMN_TITLE, "John");
cv.put(COLUMN_IMG_OUTSIDE, R.drawable.john_photo);
db.insert(DB_TABLE, null, cv));

Then with SimpleCursorAdapter I fill the list from names and their photo

SimpleCursorAdapter scAdapter;
String[] from = new String[] { DataBase.COLUMN_IMG_OUTSIDE,DataBase.COLUMN_TITLE};
int[] to = new int[] { R.id.img, R.id.text1, };

cursor = db.getAll();
startManagingCursor(cursor);

scAdapter = new SimpleCursorAdapter(ListOfItems.this, R.layout.list, cursor, from, to);
listView.setAdapter(scAdapter);

All is work, but when i want to add record to DB and choose a picture from Galery, i don't know how to save it in DB. I think i can save path to file like String path = "/sdcard/DCIM/Camera/IMG20130222_008.jpg"; But it is proble when i will fill list, becouse in DB image is saving like integer value. Sorry for my english =(

sschrass
  • 7,014
  • 6
  • 43
  • 62
Kostya Khuta
  • 1,846
  • 6
  • 26
  • 48

1 Answers1

1

Maybe you should try to save the whole image into db as blob?

See Android How to save camera images in database and display another activity in list view?

In this case you have to write your own CursorAdapter, then see this
Images in SimpleCursorAdapter

Community
  • 1
  • 1
Alessandro Alessandra
  • 1,065
  • 12
  • 18
  • I think that ican add one column in BD and save there a path to picture. Then write an own adapter where i check in what column is a image. If column integer is empty make next _italic_ **bold** `File imgFile = new File(path); Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); myImageView.setImageBitmap(myBitmap);` – Kostya Khuta Feb 23 '13 at 15:41
  • Yes, a custom adapter is the way to go. Personally I don't prefer using blobs to store images, but storing image paths is my first choice whenever possible. – Alessandro Alessandra Feb 24 '13 at 03:11