每次添加任务时,我的程序都将要执行的任务列表,该程序应将其保存在数据库中。
我遇到的问题是它不会更新以前保存的任务。
每当我登录该应用程序时,我都应该找到将它们添加到数据库中的任务。
我不知道问题出在哪里。
这是我的代码:
Todo 类:
public class Todo implements Parcelable
{
private String title;
private String status;
private String priority;
private String date;
private String time;
}
TodoDAO 类:
public long updateTodo (Todo todo)
{
db = dbHelper.getWritableDatabase();
String whereClause = TodoTable.COLUMN_NAME_TITLE + " =? " + TodoTable.COLUMN_NAME_STATUS + " =? "
+TodoTable.COLUMN_NAME_PRIORITY + " =? "+ TodoTable.COLUMN_NAME_DATE+ " =? "
+TodoTable.COLUMN_NAME_TIME + " =? " ;
String whereArgu [] = {todo.getTitle() ,todo.getStatus() , todo.getPriority() , todo.getDate() , todo.getTime() };
ContentValues values = changeTodoToContentobject( todo);
return db.update(TodoTable.TABLE_NAME , values, whereClause , whereArgu );
}
TodoDBHelper 类:
public class TodoDBHelper extends SQLiteOpenHelper implements Contract
{
private static final String DATABASE_NAME = "todo.db";
private static final int VERSION = 1;
private static final String SQL_CREATE_TODO_TABLE =
" CREATE TABLE " + TodoTable.TABLE_NAME +
" ( " + TodoTable._ID + " INTEGER PRIMARY KEY AUTOINCREMENT , "
+ TodoTable.COLUMN_NAME_TITLE + " TEXT , "+
TodoTable.COLUMN_NAME_STATUS + " TEXT , "+
TodoTable.COLUMN_NAME_PRIORITY + " TEXT , "+
TodoTable.COLUMN_NAME_DATE + " TEXT , "+
TodoTable.COLUMN_NAME_TIME + " TEXT ); " ;
private static final String SQL_DELETE_TODO_TABLE =
" DROP TABLE IF EXISTS " + TodoTable.TABLE_NAME + " ; " ;
public TodoDBHelper(Context context) {
super(context, DATABASE_NAME, null, VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL_CREATE_TODO_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(SQL_DELETE_TODO_TABLE);
onCreate(db);
}
}
界面合同:
public interface Contract {
class TodoTable implements BaseColumns{
public static final String TABLE_NAME = "todo";
public static final String COLUMN_NAME_STATUS = "status";
public static final String COLUMN_NAME_PRIORITY = "priority";
public static final String COLUMN_NAME_TITLE = "title";
public static final String COLUMN_NAME_DATE= "date";
public static final String COLUMN_NAME_TIME = "time";
}