简体   繁体   中英

Can't update data for my list view

I'm currently trying to add a feature to my app so I can allow my users to edit the data which is used to populate an item for my list view which is included in my Payments class.

Whenever I enter the changes I wish to make and press Accept, my list view doesn't update with the new edited data.

Below is the data for my Add Payments class.

    public void acceptClicked(View view)
    {
        failFlag = false;
        checkEditTexts();
        // if all are fine
        if (failFlag == false)
        {
            MOSDatabase db = new MOSDatabase(this);
            SQLiteDatabase datab = db.getWritableDatabase();
            convertToString();
            convertIntToString();

            sPaymentDate = sPaymentYear + sPaymentMonth + sPaymentDay;

            ContentValues vals = new ContentValues();
            vals.put("PTITLE", sTitle);
            vals.put("PDAY", sPaymentDay);
            vals.put("PMONTH", sPaymentMonth);
            vals.put("PYEAR", sPaymentYear);
            vals.put("PA", sAmount);
            vals.put("RMIN", sReminderMin);
            vals.put("RHOUR", sReminderHour);
            vals.put("RDAY", sReminderDay);
            vals.put("RMONTH", sReminderMonth);
            vals.put("RYEAR", sReminderYear);
            vals.put("DATE", sPaymentDate);

            if (checkbox.isChecked())
            {
                createAlarm();
            }

            if(itemInfo == false)
            {

                datab.insert("PaymentTable", null, vals);
                datab.close();
            }

            if(itemInfo == true)
            {
                datab.update("PaymentTable", vals, "PTITLE", null);
            }

            Intent openReminder = new Intent("com.studentbudget.PAYMENTS");
            startActivity(openReminder);
            finish();
        }
    }

The convertIntToString method converts the reminderDay/Month/Year etc to the string versions (sReminderDay/Month/Year etC) if I'm adding a new payment otherwise it uses iPaymentDay, iPaymentMonth, iPaymentYear, etc.

I've tried this a couple of times originally I was using String[]{"ITITLE} for the last parameter in the datab.update method but it wasn't working.

Edit (27/8/13)

I've tried the code which was posted by bakriOnFire, it updates everything apart from the title of the item.

I've also tried changing the 3rd parameter to 'null'. This allowed me to edit the title HOWEVER it edited all the items in my list view.

Can someone tell me how to update all of the fields for the item for my list view? Thanks for any solutions posted.

Edit (28/8/13)

Edited the title. The only column which doesn't update is the first column.

Edit (28/8/13)

Added screen shots

付款活动中的列表视图

添加付款活动

The first image shows the list view on the Payments Activity, the second image shows the Add Payments activity.

The third parameter in the update is a filter provided for updation, to which you've given the value as PTITLE . Its not gonna match to anything as it is the column name. You are trying to update the rows where the PTITLE is equal to sTitle, so the update should be as-

datab.update("PaymentTable", vals, "PTITLE='"+sTitle+"'", null);

I m not sure if this is what u want to do, but hope it may give you some hint.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM