I\'m having trouble closing my alert dialog. I am using a layout inflator to make the dialog, so I\'m not sure how I would go about closing the thing after I\'m done with it
Try this:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
View dialogView = inflater.inflate(R.layout.brush_opts_dialog,null);
builder.setView(dialogView);
closeBtn = (Button)dialogView.findViewById(R.id.close_btn);
final AlertDialog dialog = builder.create();
closeBtn .setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
You should use the AlertDialog.Builder to "build" the Alert Dialog itself. Then, call the create() method on the AlertDialog.Builder object. This method returns an AlertDialog object, which allows you to call dismiss().
You should not have to create it multiple times, nor use any DialogInterface objects. This works for me. Let me know how it goes for you.