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
use this code in your class:
Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom);
((Button) dialog.findViewById(R.id.button))
.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
and create custom.xml, then paste this code inside it:
source: https://www.mkyong.com/android/android-custom-dialog-example/
and if you do not like above code, so see below link: http://thedeveloperworldisyours.com/android/prevent-alertdialog-closing-button-clicked/