0

我有一个 ListFragment 上面有复选框......

public class ViewOrderLineFragment : ListFragment {
      public override bool OnOptionsItemSelected(IMenuItem item){
            switch (item.TitleFormatted.ToString()){
                case "Add":
                   //stuff here
                    break;
                case "Edit":
                        var dialog = new ConfirmationFragment(Activity);
                        dialog.Show(FragmentManager, null);
                    break;
            }

            return base.OnOptionsItemSelected(item);
        }
       public void DoPositiveClick(){=
           DeletedSelectedItems();=
        }

        public void DoNegativeClick()={
            // Do stuff here.
            //Log.Info("FragmentAlertDialog", "Negative click!");
        }

        void DeletedSelectedItems={
           //do stuff here
         }
}

当我选择一些项目并按下删除按钮时,它会提示用户“你确定吗?”

这是我的 DialogFragment 代码。

public class ConfirmationFragment : DialogFragment { 
Context _context;
        public ConfirmationFragment(Context context) {
            _context = context;   
        }
public override Dialog OnCreateDialog(Bundle savedState){
 return new AlertDialog.Builder(Activity)
                //.SetIcon(Resource.Drawable.alert_dialog_icon)
                //.SetTitle(title)
            .SetPositiveButton("Yes", (sender, e) =>
            {
                ((ViewOrderLineFragment)Activity).DoPositiveClick();
            })
            .SetNegativeButton("No", (sender, e) =>
            {
                ((ViewOrderLineFragment)Activity).DoNegativeClick();
            }).Create();
        }
}

错误: Cannot convert type 'Android.App.Activity' to 'OTCMobile.Screens.ViewOrderLineFragment'

在线的((ViewOrderLineFragment)Activity).DoPositiveClick();

我按照这个示例这个链接

任何替代解决方案?

4

1 回答 1

0

我报废了 ConfirmationFragment ..

这对我有用。

public override bool OnOptionsItemSelected(IMenuItem item) {
        switch (item.TitleFormatted.ToString()) {
            case "Add":
               //some stuff
                break;
            case "Edit":
              var confirmDialog = new AlertDialog.Builder(this.Activity)
                        //.SetIcon(Resource.Drawable.alert_dialog_icon)
                        .SetTitle("Are you sure you want to delete all selected?")
                    .SetPositiveButton("Yes", (sender, e) =>
                    {
                        DoPositiveClick();
                    })
                    .SetNegativeButton("No", (sender, e) =>
                    {
                        DoNegativeClick();
                    }).Create();
                    confirmDialog.Show();

                }
                break;
        }
        return base.OnOptionsItemSelected(item);
    }
于 2013-04-15T02:25:52.480 回答