Add OnDateChangedListener to DatePicker, Android

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		// 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(R.id.datePicker1);
		datePicker.init(year , monthOfYear, dayOfMonth, dateSetListener);
		putDate();
	}

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

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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