2017-01-30 125 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

非常感謝它爲我工作。 –