【发布时间】:2014-06-27 23:21:55
【问题描述】:
是这样吗。我有这个gridview。我想将其项目保存为 sqlite 中的 blob。所以当我在 sqlite 中打开保存数据列表时,我只需加载保存 items 并将 adapter.notifyDataSetChanged 调用到我的 gridview
我试过这个但我收到NotSerializableException 错误
列表项 = new ArrayList();
public static byte[] serializeObject(Object o) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(o);
out.close();
// Get the bytes of the serialized object
byte[] buf = bos.toByteArray();
return buf;
} catch (IOException ioe) {
Log.e("serializeObject", "error", ioe);
return null;
}
}
我的插入行
public long insertRow(byte[] data) {
/*
* CHANGE 3:
*/
// TODO: Update data in the row with new fields.
// TODO: Also change the function's arguments to be what you need!
// Create row's data:
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_DATA, data);
// Insert it into the database.
return db.insert(DATABASE_TABLE, null, initialValues);
}
然后我插入序列化对象
myDB.insertRow(MyDBAdapter.serializeObject(items));
我也很困惑。我应该保存适配器还是项目列表?
【问题讨论】: