0

(名前、数量、所有者、ステータス) を持つアイテムのレコード ストアがあります。

ユーザーがイベントをトリガーしたときに、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たが、明らかにこれは最初のものの範囲外です

あなたが助けてくれることを願っていますか?

4

1 に答える 1

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);
}
于 2010-04-13T20:16:49.440 に答える