xamarin/Xamarin.Forms
View on GitHub[Bug] Android TimePickerRenderer dialog positive button handler not triggered
Open
#13,022 opened on Dec 2, 2020
a/customrenderera/timepickere/2 :clock2:help wantedp/Androidt/bug :bug:up-for-grabs
Description
Description
When implementing a custom renderer for the TimePicker in Android to intercept whether the dialogs OK button is pressed, the handler is not triggered for the DialogButtonType.Positive. Negative and Neutral button handlers are triggered.
The same code is working for DatePickerRenderer
Steps to Reproduce
protected override TimePickerDialog CreateTimePickerDialog(int hours, int minutes)
{
dialog = new TimePickerDialog(Context, this, hours, minutes, true);
dialog.SetButton((int) DialogButtonType.Negative,
Context.Resources.GetString(global::Android.Resource.String.Cancel), OnCancel);
dialog.SetButton((int) DialogButtonType.Positive,
Context.Resources.GetString(global::Android.Resource.String.Ok), OnOk);
return dialog;
}
private void OnCancel(object sender, DialogClickEventArgs e)
{
_element.Unfocus();
}
private void OnOk(object sender, EventArgs eventArgs)
{
_element.Unfocus();
}
Expected Behavior
When clicking the OK button OnOk is called. When clicking the Cancel button OnCancel is called.
Actual Behavior
When clicking the OK button OnOk is NOT called. When clicking the Cancel button OnCancel is called.
Basic Information
- Version with issue: 4.8.0.1678
- Last known good version: -
- Platform Target Frameworks:
- Android: TargetSDK: 30
Workaround
Instead I need to use the following code in my control:
this.PropertyChanged += (sender, args) =>
{
if (Device.RuntimePlatform != Device.Android || args.PropertyName != "Time")
{
return;
}
CallOnOk();
};