我正在尝试创建一个任务管理应用程序,我需要为将要创建的每个任务设置截止日期。我可以将选定的日期保存在数据库中,但是当我更新它时,我遇到了问题。我正在尝试在 datepicker 视图中获取相同的日期,该日期使用光标保存在数据库中。有人可以帮帮我吗?谢谢
我的代码:
if(tasksID>0){
db = new TodoTask_Database(getApplicationContext());
Cursor c = db.getTaskDetails(tasksID);
db.close();
datePicker.init(Year, month, day, null);
dueDate = c.getString(0);
}
else {
datePicker.init(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth(),
new OnDateChangedListener() {
public void onDateChanged(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
Year=year;
month= monthOfYear+1;
day= dayOfMonth;
dueDate = +Year+"-"+month+"-"+day;
}
});
}
okBtn = (Button)findViewById(R.id.okBtn);
okBtn.setOnClickListener(this);
cancelBtn = (Button)findViewById(R.id.cancelBtn);
cancelBtn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
long mTaskID_FromDetails = TaskId_FromDetails;
long task_ID = Task_ID;
switch(v.getId()){
case R.id.okBtn:
Intent passtomain = new Intent(getApplicationContext(), Main_Activity.class);
db = new TodoTask_Database(getApplicationContext());
if(!db.didTaskDetailsExist(task_ID)){
db.addTaskDetails(dueDate,
mTaskID_FromDetails);
}
else{
//facing issue here how to get same date in date picker from database and update after selecting it again?
datePicker.init(Year, month, day,
new OnDateChangedListener() {
public void onDateChanged(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
Year=year;
month= monthOfYear+1;
day= dayOfMonth;
dueDate = +Year+"-"+month+"-"+day;
}
});
db.updateTaskDetails(task_ID, dueDate);
}
startActivity(passtomain);
db.close();
break;