Browse Source

Added the ability to not dismiss the dialog when actio buttons are pressed.

Aidan Follestad 10 years ago
parent
commit
7b5e57f472
2 changed files with 24 additions and 0 deletions
  1. 10 0
      README.md
  2. 14 0
      library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

+ 10 - 0
README.md

@@ -309,3 +309,13 @@ dialog.show();
 dialog.hideActions();
 dialog.showActions();
 ```
+
+If you don't want the dialog to automatically be dismissed when an action button is pressed:
+
+```java
+MaterialDialog dialog new MaterialDialog.Builder(this)
+        // ... other initialization
+        .dismissOnActionPress(false)
+        .build()
+        .show();
+```

+ 14 - 0
library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -63,6 +63,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
     private Typeface mediumFont;
     private ItemProcessor mItemProcessor;
     private boolean hideActions;
+    private boolean dismissOnActionPress;
 
     MaterialDialog(Builder builder) {
         super(new ContextThemeWrapper(builder.context, builder.theme == Theme.LIGHT ? R.style.Light : R.style.Dark));
@@ -471,6 +472,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
         protected Integer[] selectedIndicies = null;
         protected ItemProcessor itemProcessor;
         protected boolean hideActions;
+        protected boolean dismissOnActionPress = true;
 
         public Builder(@NonNull Activity context) {
             this.context = context;
@@ -697,6 +699,18 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
             return this;
         }
 
+        /**
+         * This defaults to true. If set to false, the dialog will not automatically be dismissed
+         * when an action button is pressed.
+         *
+         * @param dismiss Whether or not to dismiss the dialog.
+         * @return The Builder instance so you can chain calls to it.
+         */
+        public Builder dismissOnActionPress(boolean dismiss) {
+            this.dismissOnActionPress = dismiss;
+            return this;
+        }
+
         public MaterialDialog build() {
             return new MaterialDialog(this);
         }