Forum Xamarin.Android

TimePickerDialog and custom buttons problem. Please, help.

Hello Everyone,
I have a time picker dialog in a fragment. When clicking OK button in the dialog the TimeSelectedListener() fires. All is good.

Now, if I want to change the title of the default button I use the dialog.SetButton("NewName", button1Listener); line. It is commented in the code below. The problem is - the TimeSelectedListener listener stops firing. Obviously the button1Listener fires now. I do not know how to get the time selected by user in this case. What am I missing, please?

Second question, probably related. If I need to add another button "extra button", how can I read the time selected if a user clicks this new button. Currently, as expected the button3Listener fires.

Thank you very much and I hope someone can help me understand what I am missing here.

    TimePickerDialog dialog = new TimePickerDialog(Activity, TimeSelectedListener, DateTime.Now.Hour, DateTime.Now.Minute, false);

    //dialog.SetButton("NewName", button1Listener);  - this stops listener from firing.

    dialog.SetButton3("extra button", button3Listener);


  TimeSelectedListener (object sender, TimePickerDialog.TimeSetEventArgs e)
    var h = e.HourOfDay;
    var m = e.Minute;

  private void button3Listener(object sender, DialogClickEventArgs e)
    //some code here

  private void button1Listener(object sender, DialogClickEventArgs e)
    //some code here


  • stesvisstesvis USMember ✭✭✭✭

    @Michael_Shapiro did you ever figure it out? Same issue here...

  • Michael_ShapiroMichael_Shapiro USMember ✭✭✭

    Never found the answer. I ended up re-evaluating how I present the dialog all together and my time picker dialog is now a custom build one. I have a custom view with all the necessary widgets (NumberPickers) to represent the time picker. I then instantiate an AlertDialog and use the SetView() to load my custom view. NumebrPickers fire ValueChange event where I read the time user selected.

Sign In or Register to comment.