瀏覽代碼

Allowed entries to be instances of CharSequence instead of forcing them to be of the String subclass. It continues to work with previous code and also now allows to use it with entries retrieved from xml attributes using TypedArray.getTextArray()

Juan Ramon Gonzalez Gonzalez 10 年之前
父節點
當前提交
2a9e09cbe6

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

@@ -61,7 +61,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
     private ListCallback listCallbackSingle;
     private ListCallbackMulti listCallbackMulti;
     private View customView;
-    private String[] items;
+    private CharSequence[] items;
     private boolean isStacked;
     private int selectedIndex;
     private Integer[] selectedIndices;
@@ -456,8 +456,8 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
     }
 
     private void sendMultichoiceCallback() {
-        List<Integer> selectedIndices = new ArrayList<Integer>();
-        List<String> selectedTitles = new ArrayList<String>();
+        List<Integer> selectedIndices = new ArrayList<>();
+        List<String> selectedTitles = new ArrayList<>();
         LinearLayout list = (LinearLayout) view.findViewById(R.id.customViewFrame);
         for (int i = 1; i < list.getChildCount(); i++) {
             View itemView = list.getChildAt(i);
@@ -470,7 +470,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
         }
         listCallbackMulti.onSelection(this,
                 selectedIndices.toArray(new Integer[selectedIndices.size()]),
-                selectedTitles.toArray(new String[selectedTitles.size()]));
+                selectedTitles.toArray(new CharSequence[selectedTitles.size()]));
     }
 
     @Override
@@ -542,7 +542,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
         protected Alignment contentAlignment = Alignment.LEFT;
         protected int titleColor = -1;
         protected CharSequence content;
-        protected String[] items;
+        protected CharSequence[] items;
         protected CharSequence positiveText;
         protected CharSequence neutralText;
         protected CharSequence negativeText;
@@ -680,7 +680,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
             return this;
         }
 
-        public Builder items(String[] items) {
+        public Builder items(CharSequence[] items) {
             this.items = items;
             return this;
         }
@@ -961,7 +961,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
         ((TextView) view.findViewById(R.id.content)).setText(content);
     }
 
-    public final void setItems(String[] items) {
+    public final void setItems(CharSequence[] items) {
         this.items = items;
         invalidateList();
     }
@@ -972,7 +972,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
     }
 
     public static interface ListCallbackMulti {
-        void onSelection(MaterialDialog dialog, Integer[] which, String[] text);
+        void onSelection(MaterialDialog dialog, Integer[] which, CharSequence[] text);
     }
 
     public static interface SimpleCallback {

+ 2 - 2
library/src/main/java/com/afollestad/materialdialogs/list/ItemProcessor.java

@@ -40,7 +40,7 @@ public abstract class ItemProcessor {
      * @param itemText The text associated with the current item from the array passed into items() from the Builder.
      * @param view The inflated view for the current item.
      */
-    protected abstract void onViewInflated(int forIndex, String itemText, View view);
+    protected abstract void onViewInflated(int forIndex, CharSequence itemText, View view);
 
     /**
      * Used by MaterialDialog to inflate a list item view that will be displayed in a list.
@@ -48,7 +48,7 @@ public abstract class ItemProcessor {
      * @param forIndex The index of the item being inflated.
      * @param itemText The text associated with the current item from the array passed into items() from the Builder.
      */
-    public final View inflateItem(int forIndex, String itemText) {
+    public final View inflateItem(int forIndex, CharSequence itemText) {
         int itemLayout = getLayout(forIndex);
         if (itemLayout == 0) itemLayout = defaultLayout;
         View view = li.inflate(itemLayout, null);

+ 1 - 1
sample/src/main/java/com/afollestad/materialdialogssample/ButtonItemProcessor.java

@@ -26,7 +26,7 @@ public class ButtonItemProcessor extends ItemProcessor implements View.OnClickLi
     }
 
     @Override
-    protected void onViewInflated(int forIndex, String itemText, View view) {
+    protected void onViewInflated(int forIndex, CharSequence itemText, View view) {
         ((TextView) view.findViewById(R.id.title)).setText(itemText + " (" + forIndex + ")");
         Button button = (Button) view.findViewById(R.id.button);
         button.setTag(forIndex);

+ 1 - 1
sample/src/main/java/com/afollestad/materialdialogssample/MainActivity.java

@@ -266,7 +266,7 @@ public class MainActivity extends ActionBarActivity {
                 .items(R.array.socialNetworks)
                 .itemsCallbackMultiChoice(new Integer[]{1, 3}, new MaterialDialog.ListCallbackMulti() {
                     @Override
-                    public void onSelection(MaterialDialog dialog, Integer[] which, String[] text) {
+                    public void onSelection(MaterialDialog dialog, Integer[] which, CharSequence[] text) {
                         StringBuilder str = new StringBuilder();
                         for (int i = 0; i < which.length; i++) {
                             str.append(which[i]);