瀏覽代碼

Merge remote-tracking branch 'origin/master'

Aidan Follestad 10 年之前
父節點
當前提交
e56df7fa79
共有 1 個文件被更改,包括 17 次插入0 次删除
  1. 17 0
      library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

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

@@ -71,6 +71,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
     protected View negativeButton;
     protected boolean isStacked;
     protected boolean alwaysCallMultiChoiceCallback;
+    protected boolean alwaysCallSingleChoiceCallback;
     protected final int defaultItemColor;
     protected ListType listType;
     protected List<Integer> selectedIndicesList;
@@ -202,6 +203,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
                 // Determine list type
                 if (mBuilder.listCallbackSingle != null) {
                     listType = ListType.SINGLE;
+                    alwaysCallSingleChoiceCallback = builder.alwaysCallSingleChoiceCallback;
                 } else if (mBuilder.listCallbackMulti != null) {
                     listType = ListType.MULTI;
                     if (mBuilder.selectedIndices != null) {
@@ -787,6 +789,8 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
                     if (mBuilder.autoDismiss && mBuilder.positiveText == null) {
                         dismiss();
                         sendSingleChoiceCallback(v);
+                    } else if (alwaysCallSingleChoiceCallback) {
+                        sendSingleChoiceCallback(v);
                     }
                 } else if (mBuilder.listCallbackMulti != null) {
                     CheckBox cb = (CheckBox) ((LinearLayout) v).getChildAt(0);
@@ -825,6 +829,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
         protected ListCallback listCallbackSingle;
         protected ListCallbackMulti listCallbackMulti;
         protected boolean alwaysCallMultiChoiceCallback = false;
+        protected boolean alwaysCallSingleChoiceCallback = false;
         protected Theme theme = Theme.LIGHT;
         protected boolean cancelable = true;
         protected float contentLineSpacingMultiplier = 1.3f;
@@ -1019,6 +1024,18 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
             return this;
         }
 
+        /**
+         * By default, the single choice callback is only called when the user clicks the positive button
+         * or if there are no buttons. Call this to force it to always call on item clicks even if the
+         * positive button exists.
+         *
+         * @return The Builder instance so you can chain calls to it.
+         */
+        public Builder alwaysCallSingleChoiceCallback() {
+            this.alwaysCallSingleChoiceCallback = true;
+            return this;
+        }
+
         /**
          * Pass null for the selected indices to leave all options unselected initially. Otherwise pass
          * an array of indices that will be selected initially.