Im getting problems to get the images from SQlite and put on a ListView, well I can fill my ListView with the correct data but the image is all the same.
Where is public variables:
public byte[] BlobImage;
Bitmap bitmapCnt;
Function to Fill the ListView
public void RefreshListView() {
SimpleCursorAdapter adap;
ListView lstContacts = (ListView) findViewById(R.id.lst_contacts);
DBhelper dh = new DBhelper(this);
dh.open();
SQLiteDatabase mDb = dh.retriveCntDetailsCursor();
Cursor cur = mDb.rawQuery("select * from contacts", null);
MatrixCursor mMatrixCursor = new MatrixCursor(new String[]{"_id", "name", "number", "photo"});
adap = new SimpleCursorAdapter(
getBaseContext(),
R.layout.lv_layout,
null,
new String[]{"name", "number", "photo"},
new int[]{R.id.tv_name, R.id.tv_number, R.id.iv_photo}, 0);
if (cur.moveToFirst()) {
do {
BlobImage = cur.getBlob(1);
adap.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int i) {
if (view.getId() == R.id.iv_photo) {
byte[] Blobdata = BlobImage;
bitmapCnt = Bitmap.createScaledBitmap(BitmapFactory.decodeByteArray(
Blobdata, 0, Blobdata.length), 150, 150, false);
((ImageView) view).setImageBitmap(bitmapCnt);
return true;
} else {
return false;
}
}
});
mMatrixCursor.addRow(new Object[]{Long.toString(cur.getLong(0)),
cur.getString(2),
cur.getString(3),
bitmapCnt
});
} while (cur.moveToNext());
}
cur.close();
dh.close();
lstContacts.setAdapter(adap);
adap.swapCursor(mMatrixCursor);
}
Where is a print of my ListView:
As you can see all the photos are the same, they are all the same of the last contact. Im new in Android, please try help me I really need do this. Sorry my english and thanks for the help.
Aucun commentaire:
Enregistrer un commentaire