简体   繁体   English

无法更新我的列表视图的数据

[英]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. 我目前正在尝试向我的应用程序添加功能,以便允许我的用户编辑用于填充我的Payments类中的列表视图项目的数据。

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. 如果我要添加新的付款,则convertIntToString方法会将hinterDay / Month / Year等转换为字符串版本(sReminderDay / Month / Year等),否则它将使用iPaymentDay,iPaymentMonth,iPaymentYear等。

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. 我最初尝试过几次,但是我在datab.update方法中的最后一个参数上使用了String [] {“ ITITLE},但它没有用。

Edit (27/8/13) 编辑(27/8/13)

I've tried the code which was posted by bakriOnFire, it updates everything apart from the title of the item. 我尝试了bakriOnFire发布的代码,它更新了除项目标题以外的所有内容。

I've also tried changing the 3rd parameter to 'null'. 我也尝试将第三个参数更改为“ 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) 编辑(28/8/13)

Edited the title. 编辑标题。 The only column which doesn't update is the first column. 第一列是唯一不更新的列。

Edit (28/8/13) 编辑(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. 第一个图像显示Payments活动上的列表视图,第二个图像显示Add Payments活动。

The third parameter in the update is a filter provided for updation, to which you've given the value as PTITLE . update的第三个参数是为更新提供的过滤器,您已将其赋予值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- 您正在尝试更新PTITLE等于sTitle的行,因此更新应为-

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. 我不确定这是否是您要执行的操作,但希望它可以给您一些提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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