Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material dialog library - prevent dismissing/closing the dialog on onPositive function call

I am using this Material Dialog library and when I click the positive button, the onPositive function is called and the dialog is closed. How can I prevent the dialog from closing/dismissing?

Thanks for answers.

like image 810
Ololoking Avatar asked Mar 06 '15 23:03

Ololoking


2 Answers

.autoDismiss no longer exists. You should use .setCancelable(false) instead.

  @NonNull
  @Override
  public MaterialAlertDialogBuilder setCancelable(boolean cancelable) {
    return (MaterialAlertDialogBuilder) super.setCancelable(cancelable);
  }
like image 88
Pedro Sequeira Avatar answered Oct 03 '22 15:10

Pedro Sequeira


Add autoDismiss(false) and dismiss the dialog manually in callback method.

  new MaterialDialog.Builder(mainActivity)
            .title(R.string.title)
            .autoDismiss(false)
            .content(R.string.content)
            .positiveText(R.string.positive)
            .negativeText(R.string.negative)
            .positiveColor(setColor())
            .onPositive((dialog, which) => {
                // do something positive here
                dialog.dismiss();
            })
            .onNegative((dialog, which) => {
                // do something negative here
                dialog.dismiss();
            })
            .negativeColor(setColor())
            .typeface(titleAndActions, contentAndListItems)
            .build()
            .show();
like image 22
Djordje Tankosic Avatar answered Oct 03 '22 16:10

Djordje Tankosic