单击确定按钮时,AlertDialog未关闭 - C#xamarin

时间:2017-01-30 13:16:24

标签: android listview c#-4.0

enter image description here

大家都在列表视图中有两个按钮。当我点击拒绝按钮时,Alertdialog将来到那里我必须输入原因..在确定后输入原因点击AlertDialog应该解雇。

每件东西都保存到DB ..但是警告对话框没有关闭...而是在进入三次关闭之后...我已经在下面找到了我的代码。

      btnReject.Click += delegate
            {
                var currentItem = item;
                Console.WriteLine(position);


                AlertDialog.Builder alert = new AlertDialog.Builder(this.context);
                LayoutInflater inflater = Application.Context.GetSystemService(Context.LayoutInflaterService) as LayoutInflater;
                View viewdialog = inflater.Inflate(Resource.Layout.RejectJobsAlertDialog, null);
                EditText getreason = viewdialog.FindViewById<EditText>(Resource.Id.Reason);
                alert.SetTitle("Reject Reason ");
                alert.SetView(viewdialog);
                alert.SetPositiveButton("Ok", (senderAlert, args) =>
                {

                    item.RejectedReason = getreason.Text;
                    sharedasproxy.MobileJobdetailsUpdate(item, BASE_URL + "/xxxxx");
                    Toast.MakeText(this.context, "success!", ToastLength.Short).Show();
                    btnReject.Visibility = ViewStates.Invisible;
                    btnAccept.Visibility = ViewStates.Visible;

                    dialog.Cancel();
                });

                alert.SetNegativeButton("Cancel", (senderAlert, args) =>
                {
                    Toast.MakeText(this.context, "Cancelled!", ToastLength.Short).Show();
                    CloseDialog();
                });


                dialog = alert.Create();


                dialog.Show();




            };

1 个答案:

答案 0 :(得分:2)

  • 确保按钮点击事件未多次附加。
  • 不是编写委托,而是在点击事件中调用方法。

尝试以下内容,

 if (!btnReject.HasOnClickListeners)
    {

btnReject.Click += delegate
            {
                var currentItem = item;

                AlertDialog.Builder alert = new AlertDialog.Builder(this.context);
                LayoutInflater inflater = Application.Context.GetSystemService(Context.LayoutInflaterService) as LayoutInflater;
                View viewdialog = inflater.Inflate(Resource.Layout.RejectJobsAlertDialog, null);
                EditText getreason = viewdialog.FindViewById<EditText>(Resource.Id.Reason);
                alert.SetTitle("Reject Reason ");
                alert.SetView(viewdialog);
                alert.SetPositiveButton("Ok", (senderAlert, args) =>
                {

                    item.RejectedReason = getreason.Text;
                    sharedasproxy.MobileJobdetailsUpdate(item, BASE_URL + "/xxxxx");
                    Toast.MakeText(this.context, "success!", ToastLength.Short).Show();
                    btnReject.Visibility = ViewStates.Invisible;
                    btnAccept.Visibility = ViewStates.Visible;
                    dialog.Cancel();
                });

                alert.SetNegativeButton("Cancel", (senderAlert, args) =>
                {
                    Toast.MakeText(this.context, "Cancelled!", ToastLength.Short).Show();
                    CloseDialog();
                });    

                dialog = alert.Create();
                dialog.Show();


            };
}