1

我有一段代码在单击列表项时更新表中的一行。这是代码,

    list_replace.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> Parent,View v, int Position, long id) {

            ContentValues cvs = new ContentValues();

           cvs.put(COLUMN_NAME_READING_MODE, ReadingMode);
           cvs.put(COLUMN_NAME_PASTDATETIME, StartDate);
           cvs.put("EndDateTime", CurrentDateTime);
           cvs.put(COLUMN_NAME_READINGVALUE,Reading);
           DB.update(TABLE_NAME, cvs, "_Id =" + id, null);

          DB.close();

        }
    });

但我没有在我的表中看到任何更新的记录。请纠正我。

任何帮助将不胜感激。

4

1 回答 1

1
list_replace.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> Parent,View v, int Position, long id) {

        ContentValues cvs = new ContentValues();

       cvs.put(COLUMN_NAME_READING_MODE, ReadingMode);
       cvs.put(COLUMN_NAME_PASTDATETIME, StartDate);
       cvs.put("EndDateTime", CurrentDateTime);
       cvs.put(COLUMN_NAME_READINGVALUE,Reading);
       SQLiteDatabase db = context.openOrCreateDatabase(DATABASE_NAME,
            Context.MODE_PRIVATE, null);   // add this line
       db.update(TABLE_NAME, cvs, "_Id =" + id, null);

       db.close();

    }
});
于 2013-03-14T06:39:58.907 回答