我有一个记录存储项目(名称,数量,所有者,状态)
现在当用户触发事件时,我想用“已购买”设置我的RecordStore中所有项目的状态
re = shoppingListStore.enumerateRecords(null, null, false);
while (re.hasNextElement())
{
// read current values of item
byte [] itemRecord = re.nextRecord();
// deserialise byte array
newItemObject.fromByteArray(itemRecord);
// set item status to purchased
newItemObject.setItemStatus("Purchased");
// create new bytearray and call newitemobject . tobytearray
// method to return a byte array of the objects
// (using UTF8 encoded strings~)
byte[] itemData = newItemObject.toByteArray();
// add new byte array to shoppinglist store
shoppingListStore.setRecord(re.nextRecordId(), itemData, 0, itemData.length);
}
但是我覆盖了下一条记录(使用nextRecordId)。我尝试过使用nextRecordId - 1
,但很明显这是第一个
希望你能帮忙吗?
答案 0 :(得分:3)
你试过吗?
re = shoppingListStore.enumerateRecords(null, null, false);
while (re.hasNextElement())
{
int id = re.nextRecordId();
// read current values of item
byte [] itemRecord = shoppingListStore.getRecord(id);
// deserialise byte array
newItemObject.fromByteArray(itemRecord);
// set item status to purchased
newItemObject.setItemStatus("Purchased");
// create new bytearray and call newitemobject . tobytearray method to return a byte array of the object (using UTF8 encoded strings~)
byte[] itemData = newItemObject.toByteArray();
// update shoppinglist store record with new byte array
shoppingListStore.setRecord(id, itemData, 0, itemData.length);
}