目标是显示对话框,供用户选择EditText
上的日期。
我正在努力实现将在点击时显示对话框的绑定。代码如下:
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();
}
}
但是我无法找到一种获取FragmentManager
实例的方法来调用实例化对话框的Show
方法。这可以以任何方式实施吗?
答案 0 :(得分:0)
找到了实现它的方法:
var act = (Activity) Target.Context;
dialog.Show(act.FragmentManager, "date");