ソースを参照

Add convenience methods for retrieving currently selected index(es)

Henri Sweers 10 年 前
コミット
45f376a646

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

@@ -1162,6 +1162,33 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
         return listView;
     }
 
+    /**
+     * Convenience method for getting the currently selected index of a single choice list
+     *
+     * @return Currently selected index of a single choice list, or -1 if not showing a single choice list
+     */
+    public int getSelectedIndex() {
+        if (listCallbackSingle != null) {
+            return selectedIndex;
+        } else {
+            return -1;
+        }
+    }
+
+    /**
+     * Convenience method for getting the currently selected indices of a multi choice list
+     *
+     * @return Currently selected index of a multi choice list, or null if not showing a multi choice list
+     */
+    @Nullable
+    public Integer[] getSelectedIndices() {
+        if (listCallbackMulti != null) {
+            return selectedIndices;
+        } else {
+            return null;
+        }
+    }
+
     private class MaterialDialogAdapter extends ArrayAdapter<CharSequence> {
 
         final int itemColor;