我正在尝试创建一个TaskManager
Where I have a setDate Button
,当我单击 SetDate 按钮时,它通过了我在DatePicker
布局中放置 a 的下一个 Activity 。我正在尝试设置日期,然后使用确定按钮将该设置日期传递到数据库中。
日期选择器活动:
public class Task_Details extends Activity implements OnClickListener {
DatePicker datePicker;
private DatePicker.OnDateChangedListener dateSetListener;
Button okBtn, cancelBtn;
String setDate;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.task_details);
datePicker = (DatePicker)findViewById(R.id.setDueDate);
datePicker.init(datePicker.getYear(),datePicker.getMonth(), datePicker.getDayOfMonth(), dateSetListener);
okBtn = (Button)findViewById(R.id.okBtn);
okBtn.setOnClickListener(this);
cancelBtn = (Button)findViewById(R.id.cancelBtn);
cancelBtn.setOnClickListener(this);
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.okBtn:
String returnDate = setDate();
db = new TodoTask_Database(getApplicationContext()); //Database call
db.addTaskDetails(returnDate); //Datebase method
break;
case R.id.cancelBtn:
Intent intent = new Intent(getApplicationContext(), Add_Task.class);
startActivity(intent);
break;
}
}
String setDate(){
dateSetListener = new DatePicker.OnDateChangedListener() {
public void onDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
System.out.println(+ year+"-"+ monthOfYear+"-"+ dayOfMonth);
String Year=Integer.toString(year);
String Month=Integer.toString(monthOfYear);
String Day=Integer.toString(dayOfMonth);
System.out.println(Year+"-"+Month+"-"+Day);
}
};
return setDate;
}
}
我正在尝试获取日期并保存到数据库中。