Reputation: 275
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
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
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