[mono-android] Events for date and time picker
Jonathan Pryor
jonp at xamarin.com
Wed Nov 30 15:55:03 EST 2011
On Nov 19, 2011, at 8:38 PM, Paul F. Johnson wrote:
> Should I still be using a listener and if so, how?
Yes, set via the DatePicker.Init() method:
http://androidapi.xamarin.com/monodoc.ashx?link=M%3aAndroid.Widget.DatePicker.Init(System.Int32%2cSystem.Int32%2cSystem.Int32%2cAndroid.Widget.DatePicker.IOnDateChangedListener)
You'll need to implement the DatePicker.IOnDateChangedListener interface:
class DateChangedListener : Java.Lang.Object, DatePicker.IOnDateChangedListener {
Action<DatePicker, int, int, int> callback;
public DateChangedListener (Action<DatePicker, int, int, int> callback)
{
this.callback = callback;
}
public void OnDateChanged (DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
callback (view, year, monthOfYear, dayOfMonth);
}
}
I don't know what context you need, but to use the above you would:
DatePicker dp = ...;
dp.Init (2011, 11, 30, new DateChangedListener ((picker, year, month, day) => {
// ...
}));
- Jon
More information about the Monodroid
mailing list