I have a screen where the user selects a Time in the screen from a TimePickerDialog
instance. But in the call back I couldn't obtain the selected date. My code is like this:
public void onSomeButtonClick(object sender, EventArgs e)
{
t = new TimePickerDialog(this, (EventHandler<TimePickerDialog.TimeSetEventArgs>)null, hour, min, false);
t.SetButton("OK", data_TimePickerCallback);
t.Show()
}
private void data_TimePickerCallback(object sender, EventArgs e)
{
int hour = ((TimePickerDialog)sender)... // How to get the Time selected here??
}
Why Am I not passing the CallBack in the Constructor? Because of this error (basically: in some versions of android, the system only puts an "Ok" button in the Dialog so if you either click Ok or click outside of the timepicker dialog, both would trigger the callback as if it was confirming), and as described there, the workaround is to add the behavior through adding a Custom Button in the picker as described in the code above.
The way I was doing before was working fine in most of the devices, but not all because of this error, and the code was approximately like this:
public void onSomeButtonClick(object sender, EventArgs e)
{
new TimePickerDialog(this, data_TimePickerCallback, hour, min, false).Show();
}
private void data_TimePickerCallback(object sender, TimePickerDialog.TimeSetEventArgs e)
{
int hour = e.HourOfDay;
int minute = e.Minute;
}
Before it was easy to get the Time but now with this change I didn't found a way inside the sender
object to get the time (the int vars minute and hour).
Edit: I tried also implementing the TimePickerDialog.IOnTimeSetListener
on my Activity class and adding the OnTimeSet(TimePicker view, int hourOfDay, int minute)
to it as the code below but still resulted in the same error:
public class CadCliente : Activity, TimePickerDialog.IOnTimeSetListener{
public void OnTimeSet(TimePicker view, int hourOfDay, int minute)
{
// handles
}
//...
public void onSomeButtonClick(object sender, EventArgs e)
{
new TimePickerDialog(this, this, hour, minute, false).Show();
}
}