无法从另一个自定义对话框

时间:2018-04-13 14:02:05

标签: android xamarin xamarin.android

我有两个自定义对话框。对话框A就像一个包含两个字段的表单。和对话框B充当验证弹出窗口,让用户知道该值是否为已使用的重复值或未知值。用户可以编辑对话框B中的字段,当他按下保存按钮时,它应该更新对话框A中的文本字段。

对话A:

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        //return customview for the fragment
        view = inflater.Inflate(Resource.Layout.AMEditSampleDialogLayout, container, false);
        tagEdit = view.FindViewById<EditText>(Resource.Id.tagEdit);
        yieldEdit = view.FindViewById<EditText>(Resource.Id.yieldEdit);
        missedYield = view.FindViewById<CheckBox>(Resource.Id.yieldMissed);
        cancel = view.FindViewById<Button>(Resource.Id.cancel);
        save = view.FindViewById<Button>(Resource.Id.save);
    }

    public void TagConfirmListener(string tag, bool forceDuplicate)
    {
        this.Activity.RunOnUiThread(() => {

            // When I debug here, I can see the value passed back but didn't update the EditText.
            view.FindViewById<EditText>(Resource.Id.tagEdit).Text = tag;
        });
        tagValid = true;
        autoCompleteOptions.Add(tag);
    }

对话B:

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        //return customview for the fragment
        View view = inflater.Inflate(Resource.Layout.ConfirmCorrectTagDialog, container, false);
        tagEdit = view.FindViewById<EditText>(Resource.Id.tagEdit);
        unit = view.FindViewById<TextView>(Resource.Id.unit);
        titleText = view.FindViewById<TextView>(Resource.Id.titleText);
        titleBackground = view.FindViewById<LinearLayout>(Resource.Id.titleBackground);
        save = view.FindViewById<Button>(Resource.Id.save);
        fixLater = view.FindViewById<CheckBox>(Resource.Id.fixLater);
        Dialog.Window.RequestFeature(WindowFeatures.NoTitle); //remove title area
        Dialog.SetCanceledOnTouchOutside(false); //dismiss window on touch outside

        tagEdit.Text = tag;
        titleText.Text = title;
        unit.Text = unitPassed;

        save.Click += delegate
        {
          this.CloseAndConfirm();
        }


    }

    private void CloseAndConfirm()
    {
        callback.TagConfirmListener(tagEdit.Text, fix.Checked);
        Dismiss();
    }

    public interface TagConfirmListener
    {
        void TagConfirmListener(string tag, bool force);
    }

我不知道为什么它不会更新,甚至尝试运行UI线程来更改它,我知道值正在传回Dialog A.

任何帮助都会受到赞赏,因为我的思绪令人难以置信。

0 个答案:

没有答案