Просмотр исходного кода

A couple things were missing on the pull request for accepting CharSequences as entries. While the code was compatible, the callbacks need to be changed to also receive CharSequence instead of String. This has now been corrected both on code, README.md and sample activity.

Juan Ramon Gonzalez Gonzalez 10 лет назад
Родитель
Сommit
7f2a5fbc30

+ 4 - 4
README.md

@@ -161,7 +161,7 @@ new MaterialDialog.Builder(this)
         .items(new String[]{"Twitter", "Google+", "Instagram", "Facebook"})
         .items(new String[]{"Twitter", "Google+", "Instagram", "Facebook"})
         .itemsCallback(new MaterialDialog.ListCallback() {
         .itemsCallback(new MaterialDialog.ListCallback() {
             @Override
             @Override
-            public void onSelection(MaterialDialog dialog, View view, int which, String text) {
+            public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
             }
             }
         })
         })
         .build()
         .build()
@@ -195,7 +195,7 @@ new MaterialDialog.Builder(this)
         .items(new String[]{"Twitter", "Google+", "Instagram", "Facebook"})
         .items(new String[]{"Twitter", "Google+", "Instagram", "Facebook"})
         .itemsCallbackSingleChoice(-1, new MaterialDialog.ListCallback() {
         .itemsCallbackSingleChoice(-1, new MaterialDialog.ListCallback() {
             @Override
             @Override
-            public void onSelection(MaterialDialog dialog, View view, int which, String text) {
+            public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
             }
             }
         })
         })
         .positiveText("Choose")
         .positiveText("Choose")
@@ -227,7 +227,7 @@ new MaterialDialog.Builder(this)
         .items(new String[]{"Twitter", "Google+", "Instagram", "Facebook"})
         .items(new String[]{"Twitter", "Google+", "Instagram", "Facebook"})
         .itemsCallbackMultiChoice(null, new MaterialDialog.ListCallbackMulti() {
         .itemsCallbackMultiChoice(null, new MaterialDialog.ListCallbackMulti() {
             @Override
             @Override
-            public void onSelection(MaterialDialog dialog, Integer[] which, String[] text) {
+            public void onSelection(MaterialDialog dialog, Integer[] which, CharSequence[] text) {
             }
             }
         })
         })
         .positiveText("Choose")
         .positiveText("Choose")
@@ -355,4 +355,4 @@ MaterialDialog dialog new MaterialDialog.Builder(this)
         .typeface(titleAndActions, contentAndListItems)
         .typeface(titleAndActions, contentAndListItems)
         .build()
         .build()
         .show();
         .show();
-```
+```

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

@@ -449,7 +449,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
             @SuppressLint("WrongViewCast")
             @SuppressLint("WrongViewCast")
             RadioButton rb = (RadioButton) itemView.findViewById(R.id.control);
             RadioButton rb = (RadioButton) itemView.findViewById(R.id.control);
             if (rb.isChecked()) {
             if (rb.isChecked()) {
-                listCallbackSingle.onSelection(this, v, i - 1, ((TextView) itemView.findViewById(R.id.title)).getText().toString());
+                listCallbackSingle.onSelection(this, v, i - 1, ((TextView) itemView.findViewById(R.id.title)).getText());
                 break;
                 break;
             }
             }
         }
         }
@@ -457,7 +457,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
 
 
     private void sendMultichoiceCallback() {
     private void sendMultichoiceCallback() {
         List<Integer> selectedIndices = new ArrayList<>();
         List<Integer> selectedIndices = new ArrayList<>();
-        List<String> selectedTitles = new ArrayList<>();
+        List<CharSequence> selectedTitles = new ArrayList<>();
         LinearLayout list = (LinearLayout) view.findViewById(R.id.customViewFrame);
         LinearLayout list = (LinearLayout) view.findViewById(R.id.customViewFrame);
         for (int i = 1; i < list.getChildCount(); i++) {
         for (int i = 1; i < list.getChildCount(); i++) {
             View itemView = list.getChildAt(i);
             View itemView = list.getChildAt(i);
@@ -465,7 +465,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
             CheckBox rb = (CheckBox) itemView.findViewById(R.id.control);
             CheckBox rb = (CheckBox) itemView.findViewById(R.id.control);
             if (rb.isChecked()) {
             if (rb.isChecked()) {
                 selectedIndices.add(i - 1);
                 selectedIndices.add(i - 1);
-                selectedTitles.add(((TextView) itemView.findViewById(R.id.title)).getText().toString());
+                selectedTitles.add(((TextView) itemView.findViewById(R.id.title)).getText());
             }
             }
         }
         }
         listCallbackMulti.onSelection(this,
         listCallbackMulti.onSelection(this,
@@ -968,7 +968,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
 
 
 
 
     public static interface ListCallback {
     public static interface ListCallback {
-        void onSelection(MaterialDialog dialog, View itemView, int which, String text);
+        void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text);
     }
     }
 
 
     public static interface ListCallbackMulti {
     public static interface ListCallbackMulti {

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

@@ -223,7 +223,7 @@ public class MainActivity extends ActionBarActivity {
                 .items(R.array.socialNetworks)
                 .items(R.array.socialNetworks)
                 .itemsCallback(new MaterialDialog.ListCallback() {
                 .itemsCallback(new MaterialDialog.ListCallback() {
                     @Override
                     @Override
-                    public void onSelection(MaterialDialog dialog, View view, int which, String text) {
+                    public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                         Toast.makeText(getApplicationContext(), which + ": " + text, Toast.LENGTH_SHORT).show();
                         Toast.makeText(getApplicationContext(), which + ": " + text, Toast.LENGTH_SHORT).show();
                     }
                     }
                 })
                 })
@@ -237,7 +237,7 @@ public class MainActivity extends ActionBarActivity {
                 .items(R.array.states)
                 .items(R.array.states)
                 .itemsCallback(new MaterialDialog.ListCallback() {
                 .itemsCallback(new MaterialDialog.ListCallback() {
                     @Override
                     @Override
-                    public void onSelection(MaterialDialog dialog, View view, int which, String text) {
+                    public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                         Toast.makeText(getApplicationContext(), which + ": " + text, Toast.LENGTH_SHORT).show();
                         Toast.makeText(getApplicationContext(), which + ": " + text, Toast.LENGTH_SHORT).show();
                     }
                     }
                 })
                 })
@@ -251,7 +251,7 @@ public class MainActivity extends ActionBarActivity {
                 .items(R.array.socialNetworks)
                 .items(R.array.socialNetworks)
                 .itemsCallbackSingleChoice(2, new MaterialDialog.ListCallback() {
                 .itemsCallbackSingleChoice(2, new MaterialDialog.ListCallback() {
                     @Override
                     @Override
-                    public void onSelection(MaterialDialog dialog, View view, int which, String text) {
+                    public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                         Toast.makeText(getApplicationContext(), which + ": " + text, Toast.LENGTH_SHORT).show();
                         Toast.makeText(getApplicationContext(), which + ": " + text, Toast.LENGTH_SHORT).show();
                     }
                     }
                 })
                 })
@@ -288,7 +288,7 @@ public class MainActivity extends ActionBarActivity {
                 .items(R.array.socialNetworks)
                 .items(R.array.socialNetworks)
                 .itemsCallback(new MaterialDialog.ListCallback() {
                 .itemsCallback(new MaterialDialog.ListCallback() {
                     @Override
                     @Override
-                    public void onSelection(MaterialDialog dialog, View view, int which, String text) {
+                    public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                         Toast.makeText(getApplicationContext(), which + ": " + text, Toast.LENGTH_SHORT).show();
                         Toast.makeText(getApplicationContext(), which + ": " + text, Toast.LENGTH_SHORT).show();
                     }
                     }
                 })
                 })