How to Close AlertDialog before Builder.Show is called

ValOkaforValOkafor USMember, University ✭✭

Can someone please show me how to close the AlertDialog below.

        AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
            builder.SetTitle("Add Professional Service");
            builder.SetItems(services, (sender, args) =>
            {
                if (services[args.Which].Equals(Constants.ChooseExistingService))
                {
                    Toast.MakeText(Activity, "Choose existing Service picked", ToastLength.Short).Show();
                }
                 else if (services[args.Which].Equals(Constants.Cancel))
                {
                    Toast.MakeText(Activity, "Cancel picked", ToastLength.Short).Show();
                    //How to close dialog Here 
                }
            });

            builder.Show();

In Java below is how it would have been dismissed

AlertDialog.Builder mBuilder = new AlertDialog.Builder(getActivity());
        mBuilder.setTitle("Add Professional Service");
        mBuilder.setItems(services, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (services[which].equals(Constants.CHOOSE_EXISTING_SERVICE)){
                    //Show existing services list
                    PickExistingService();
                    dialog.dismiss();
                }else  if (services[which].equals(Constants.CANCEL)){
                    dialog.dismiss();
                }

            }
        });

        mBuilder.show();
Tagged:

Best Answer

Answers

Sign In or Register to comment.