0

The goal is to display dialog for user to select date on tap on EditText.

I'm truing to implement binding that will show dialog on click. The code is the following:

public class EditDateBinding : BindingWrapper<EditText, DateTime>
{
    public EditDateBinding(EditText androidControl) : base(androidControl)
    {
    }

    public override void SubscribeToEvents()
    {
        Target.Click += InputClick;
    }

    private void InputClick(object sender, EventArgs args)
    {
        DateTime parsedDate = DateTime.Now;
        DateTime.TryParse(Target.Text, CultureInfo.CurrentCulture, DateTimeStyles.None, out parsedDate);

        var dialog = new DatePickerDialogFragment(Target.Context, parsedDate, OnDateSet);

        dialog.Show(
                    // Can't get fragment manager here
            , "date");
    }

    private void OnDateSet(object sender, DatePickerDialog.DateSetEventArgs e)
    {
        SetValueToView(Target, e.Date);
    }

    protected override void Dispose(bool isDisposing)
    {
        base.Dispose(isDisposing);
        if (isDisposing)
        {
            if (Target != null)
            {
                Target.Click -= InputClick;
            }
        }
    }

    protected override void SetValueToView(EditText androidControl, DateTime value)
    {
        androidControl.Text = value.ToShortDateString();
    }
}

But I cant find a way to get FragmentManager instance in order to call Show method of instantiated dialog. Can this be implemented in any way?

Sly
  • 15,046
  • 12
  • 60
  • 89
  • Generally I try to show Dialog's using the InteractionRequest pattern - see http://stackoverflow.com/questions/22639808/ for a full explanation – Stuart May 17 '15 at 05:09

1 Answers1

0

Found a way to implement it:

 var act = (Activity) Target.Context;
 dialog.Show(act.FragmentManager, "date");
Sly
  • 15,046
  • 12
  • 60
  • 89