我想检索联系人和图像并将它们显示到 ListView 中并将图像和联系人保存到数据库中,在另一个 Activity 中我想从数据库中检索带有图像的联系人并将它们显示到 ListView 中我可以检索联系人但如何保存将图像存入数据库,然后如何从数据库检索图像
我使用这种方法将数据保存到数据库
public void addBlockedNumberWithImage(String number, String name,
byte[] image) {
// Add a new blocked number
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(BLOCKLIST_NUMBER, number);
values.put(BLOCKLIST_NAME, name);
values.put(CONTACT_IMAGE, image);
/* Inserting the entry */
db.insert(TABLE_BLOCKLISTWITHIMAGE, null, values);
db.close(); // close the database connection
}
DbHelper db = new DbHelper(this);
db.addBlockedNumberWithImage(phoneNumber, name, image);
最佳答案
我不会将图像保存到数据库中,而是将图像保存到设备上的某个位置(最好是 SD 卡),并在数据库中保存每个图像的位置
然后,当您想要显示它们时,您可以简单地从数据库中检索图像的路径,并将其加载:)
关于android - 将图像保存到数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18739012/