2017-01-30 123 views
0

enter image description hereAlertDialog不关闭xamarin

您好所有具有两个在列表视图的按钮。当我点击拒绝按钮时,Alertdialog会到来,在那里我必须输入原因。在输入原因后点击OK按钮,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(); 




      }; 

回答

2
  • 确认,按钮点击事件不附多次。
  • 不是写代理,而是在click事件中调用一个方法。

尝试像下面,

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(); 


      }; 
} 
+0

非常感谢它为我工作。 –