Android sqlite update row

可紊 提交于 2019-12-04 13:08:29

Two things.

1) You need to close your cursor. Personally, I let the framwork handle that by using startManagingCursor(mYourCursor); rather than having to try and remember to do it myself.

2) Android expects your row id to be "_id", so you might try changing all your tables to use that.

Try this code:

This is in your DatabaseHelper class,

public void updateRow(long rowId, String name, String value1, String value2, String value3, String value4) {
        SQLiteDatabase db = this.getWritableDatabase();

    ContentValues args = new ContentValues();
    args.put("KEY1", name);
    args.put("KEY2", value1);
    args.put("KEY3", value2);
    args.put("KEY4", value3);
    args.put("KEY5", value4);

    db.update(TABLE_DETAILS, args, "id=" + rowId, null);
}

and use this wherever you want to update the row values.

db.updateRow(id, name, string1, string2, string3, string4);

Your Function editChild is perfectly OK.

Now the Problem Can be from Cursor Side. or regarding Database open or close.

You need to use database.update(TABLE_CHILDREN, args, "id =?",new String{String.valueOf(id)});

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!