In my application i am using date picker for user to select date.ALso i am using database in my application,if user selects 1 particular item means i will fetch data related to that item and i will show it in another screen,in that it will have 1 start date,i have to load that date as default date in date picker..But it is loading the current date as default date but not the date fetched from database..Please help me..Thanks in advance.
My code :
c = Calendar.getInstance();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd");
System.out.println("After format");
Date pickdefdate=null;
// String pickdefdatepar=null;
try {
System.out.println("Inside try="+date);
pickdefdate=sdf.parse(date); ----------->date which is fetched from database.
System.out.println("dddddddd="+pickdefdate);
c.setTime(pickdefdate); --------------------->Setting this date as current date..
System.out.println("After parse");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mYear = c.get(Calendar.YEAR); ----------as u said i am setting this value before dialog.
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
showDialog(DATE_DIALOG_ID);
protected Dialog onCreateDialog(int id)
{
switch (id) {
case DATE_DIALOG_ID:
System.out.println("in dia="+mDay);
return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay);
}
return null;
}
private DatePickerDialog.OnDateSetListener mDateSetListener =
new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
System.out.println("Inside dia");
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
}
};