我有一个 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();
我按照这个示例这个链接
任何替代解决方案?