è giusto. Ho questo gridview
. Voglio salvare il suo oggetto come blob in sqlite. così quando ho aperto l'elenco di salvare i dati in malati SQLite basta caricare il salvataggio items
e chiamare adapter.notifyDataSetChanged
alla mia gridview
Android Salva oggetto come blob in sqlite
ho provato questo, ma ho NotSerializableException
errore
Elenco articoli = 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;
}
}
mia riga di inserimento
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);
}
poi inserire l'oggetto serializzare
myDB.insertRow(MyDBAdapter.serializeObject(items));
anche io sono confuso. dovrei salvare l'adattatore o l'elenco degli articoli?
Cosa intendi? Come conservare un elenco di elementi? O come recuperarli? –
come richiamarli – user3487657
Modificato la risposta per dimostrare come recuperarli :) –