Reputation: 305
I'm having a problem on how to get the selected date from my Calendar View. I'm using Xamarin Studio which is c# and I can't use the solutions I've seen here because they're in java codes.
Does anyone know what to do?
Upvotes: 0
Views: 2798
Reputation: 3701
Just set the DateChange
Event in your view. Like following code:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
var calendar = FindViewById<CalendarView>(Resource.Id.mycalendarid);
calendar.DateChange += CalendarOnDateChange;
}
And the event method:
private void CalendarOnDateChange(object sender, CalendarView.DateChangeEventArgs args)
{
var newdatetime = new DateTime(args.Year, args.Month, args.DayOfMonth);
}
This method will be fired every time the date changed in your CalendarView
.
Option 2: You just look at the property from the calendarview:
calendar.Date
Android says following about this property (in Android it is a method):
Gets the selected date in milliseconds since January 1, 1970 00:00:00
Upvotes: 1