Add OnDateChangedListener to DatePicker, Android

	protected void onCreate(Bundle savedInstanceState)

		// Get today's date
		GregorianCalendar myCalendar = new GregorianCalendar();
		int monthOfYear = myCalendar.get(Calendar.MONTH);
		int dayOfMonth  = myCalendar.get(Calendar.DAY_OF_MONTH);
		int year		= myCalendar.get(Calendar.YEAR);

		this.myDateManager = new DateManager(myCalendar);

		DatePicker datePicker = (DatePicker) findViewById(;
		datePicker.init(year , monthOfYear, dayOfMonth, dateSetListener);

	private DatePicker.OnDateChangedListener dateSetListener = new DatePicker.OnDateChangedListener() {
		public void onDateChanged(DatePicker view, int year, int monthOfYear,
				int dayOfMonth) {
			myDateManager.setCalendar(year, monthOfYear, dayOfMonth);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s