diff --git a/catalog/java/io/material/catalog/timepicker/TimePickerMainDemoFragment.java b/catalog/java/io/material/catalog/timepicker/TimePickerMainDemoFragment.java index 360a21e9cef..47007a47c24 100644 --- a/catalog/java/io/material/catalog/timepicker/TimePickerMainDemoFragment.java +++ b/catalog/java/io/material/catalog/timepicker/TimePickerMainDemoFragment.java @@ -32,6 +32,7 @@ import android.widget.Button; import android.widget.TextView; import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; import com.google.android.material.button.MaterialButtonToggleGroup; import com.google.android.material.timepicker.MaterialTimePicker; import com.google.android.material.timepicker.TimeFormat; @@ -133,6 +134,16 @@ public View onCreateDemoView( }); }); + Fragment fragment = getParentFragmentManager().findFragmentByTag("fragment_tag"); + if (fragment instanceof MaterialTimePicker) { + MaterialTimePicker materialTimePicker = (MaterialTimePicker) fragment; + materialTimePicker.addOnPositiveButtonClickListener(dialog -> { + int newHour = materialTimePicker.getHour(); + int newMinute = materialTimePicker.getMinute(); + TimePickerMainDemoFragment.this.onTimeSet(newHour, newMinute); + }); + } + return view; }