private int mYear;
private int mMonth;
private int mDay;
static final int DATE_PICKER_ID = 1111;
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
calenderView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
showDialog(DATE_PICKER_ID);
}
});
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_PICKER_ID:
// set date picker as current date
return new DatePickerDialog(this, pickerListener , mYear, mMonth,mDay );
}
return null;
}
private DatePickerDialog.OnDateSetListener pickerListener = new DatePickerDialog.OnDateSetListener() {
// when dialog box is closed, below method will be called.
@Override
public void onDateSet(DatePicker view, int selectedYear,
int selectedMonth, int selectedDay) {
mDay = selectedDay;
mMonth = selectedMonth;
mYear = selectedYear;
Calendar c = Calendar.getInstance();
c.set(mYear, mMonth, mDay);
SimpleDateFormat df = new SimpleDateFormat("MMM-dd-yyyy");
String selectedDate = df.format(c.getTime());
calenderView.setText(selectedDate);
}
};