I have a ListFragment that has checkboxes on it...
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
}
}
When I select some items and press the delete button, it will prompt the user "R u sure ?"
Here is my code for the 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();
}
}
Error:
Cannot convert type 'Android.App.Activity' to 'OTCMobile.Screens.ViewOrderLineFragment'
On line ((ViewOrderLineFragment)Activity).DoPositiveClick();
I followed this sample this link
Any alternate solutions ?