newProgrammer
newProgrammer

Reputation: 45

Adding to Sqlite Database While looping through ArrayList

i have a simple budget program that allows u to press a PayDay button that will increase the current amount in the budget by the amount set up when the budget was made. im having trouble getting the values out of the arraylist while still being able to acutually add them to the database this is what i have so far

        for(String amount: pds)
        {
            t2.put(KEY_AMOUNT, amount);
        }

        for(String Id: bIds)
        {
            t2.put(KEY_TRANSACTION,a);
            t2.put(KEY_DATE, date);
            t2.put(KEY_CATEGORYID, Id);
        }

        ourDatabase.insert(DATABASE_TABLE2,null,t2);
        return ourDatabase;

all this does is put the last values in each list. i have tried several other ways but cant get it right any and all help is greatly apreceated

Upvotes: 1

Views: 351

Answers (1)

toadzky
toadzky

Reputation: 3846

I'm assuming that t2 is a ContentValues object. They have a single value for each key, so setting the key 12 times just overwrites each time. You need to insert after every value if you want a different record for each value. If you want them to be joined into a CSV list or something, you need to use TextUtils join method to concatenate the values. If you do that, make sure you are have your column type as TEXT.

Upvotes: 1

Related Questions