Hi,
I am trying to save the selected date in the database.
I did that with the help of date picker, now I need to save it in the database.
How to do that?
How to get the selected date and store it in the database?
Can any one help to me?
this is my code
DatePickerDialog.OnDateSetListener startdate=new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
dateAndTime.set(Calendar.YEAR, year);
dateAndTime.set(Calendar.MONTH, monthOfYear);
dateAndTime.set(Calendar.DAY_OF_MONTH, dayOfMonth);
}
};
TimePickerDialog.OnTimeSetListener t=new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay,int minute) {
dateAndTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
dateAndTime.set(Calendar.MINUTE, minute);
view.setCurrentHour(Calendar.HOUR_OF_DAY);
}
};
super.onStart();
dbHelper=new DatabaseActivity(this);
Button startbtn=(Button)findViewById(R.id.AddStartButton);
startbtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new DatePickerDialog(AddTask.this,startdate,
dateAndTime.get(Calendar.YEAR),
dateAndTime.get(Calendar.MONTH),
dateAndTime.get(Calendar.DAY_OF_MONTH)).show();
}
btn=(Button)findViewById(R.id.time);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new TimePickerDialog(Alarm.this,t,
dateAndTime.get(Calendar.HOUR_OF_DAY),
dateAndTime.get(Calendar.MINUTE),
true).show();
}
});
private DatePickerDialog.OnDateSetListener startdate = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
String date_selected = String.valueOf(monthOfYear+1)+" /"+String.valueOf(dayOfMonth)+" /"+String.valueOf(year);
Toast.makeText(AddTask.this, "Selected start Date is "+date_selected, Toast.LENGTH_SHORT).show();
}
};
});
by this way am getting and toast the selected date
Thank you friends