Rixwen
Rixwen

Reputation: 275

Android Alert Dialog won't dismiss

i make AlertDialog before some action and the AlertDialog won't dismissed after the action.

public void onClick(View v) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                    LayoutInflater inflater = getActivity().getLayoutInflater();
                    View pbview = inflater.inflate(R.layout.progress_bar, null);
                    builder.setView(pbview);

                    builder.setCancelable(true);
                    builder.create().show();
//do some stuff

builder.create().dismiss();
}

by the way my AlertDialog doesn't have any button. i want to make AlertDialog without button and automatically dismissed when the action is over.

EDIT: i changed the instance name.

Upvotes: 1

Views: 3357

Answers (4)

Praveen Sharma
Praveen Sharma

Reputation: 4348

agree with @ρяσѕρєя K make an instance of AlertDialog and modify your code as.

  AlertDialog alert ;

 alert =  dlgAlert.create();
        alert.show();
        //do some stuff

                alert.dismiss();

and if you want a custom dialog then you can use code like this :-

 final Dialog dialog = new Dialog(context);
        dialog.setContentView(R.layout.custom);
        dialog.setTitle("Title...");

        // set the custom dialog components - text, image and button


        Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
        // if button is clicked, close the custom dialog
        dialogButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        dialog.show();
      }
    });

Upvotes: 1

Jagadesh Seeram
Jagadesh Seeram

Reputation: 2664

This will create the AlertDialog you want...

AlertDialog alertDialog = dlgAlert.create();

Then try show,dismiss on your AlertDialog

alertDialog.show();
alertDialog.dismiss();

Upvotes: 0

Waseem Arain
Waseem Arain

Reputation: 1173

try that:

dlgAlert.dismiss();

or

dlgAlert.cancel();

Upvotes: 0

Jeffy Lazar
Jeffy Lazar

Reputation: 1923

only

dlgAlert.dismiss();

thats it :)

Upvotes: 0

Related Questions