|
@@ -11,10 +11,7 @@ import android.support.annotation.NonNull;
|
|
import android.support.annotation.Nullable;
|
|
import android.support.annotation.Nullable;
|
|
import android.support.annotation.StringRes;
|
|
import android.support.annotation.StringRes;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
-import android.webkit.WebView;
|
|
|
|
-import android.widget.AdapterView;
|
|
|
|
import android.widget.ListAdapter;
|
|
import android.widget.ListAdapter;
|
|
-import android.widget.ScrollView;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
@@ -37,90 +34,45 @@ public class MaterialDialogCompat {
|
|
|
|
|
|
private DialogInterface.OnClickListener onClickListener;
|
|
private DialogInterface.OnClickListener onClickListener;
|
|
|
|
|
|
- /**
|
|
|
|
- * Constructor using a context for this builder and the {@link MaterialDialog} it creates.
|
|
|
|
- */
|
|
|
|
public Builder(@NonNull Context context) {
|
|
public Builder(@NonNull Context context) {
|
|
builder = new MaterialDialog.Builder(context);
|
|
builder = new MaterialDialog.Builder(context);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set the message to display using the given resource id.
|
|
|
|
- *
|
|
|
|
- * @return This Builder object to allow for chaining of calls to set methods
|
|
|
|
- */
|
|
|
|
public Builder setMessage(@StringRes int messageId) {
|
|
public Builder setMessage(@StringRes int messageId) {
|
|
builder.content(messageId);
|
|
builder.content(messageId);
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set the message to display.
|
|
|
|
- *
|
|
|
|
- * @return This Builder object to allow for chaining of calls to set methods
|
|
|
|
- */
|
|
|
|
public Builder setMessage(@NonNull CharSequence message) {
|
|
public Builder setMessage(@NonNull CharSequence message) {
|
|
builder.content(message);
|
|
builder.content(message);
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set the title using the given resource id.
|
|
|
|
- *
|
|
|
|
- * @return This Builder object to allow for chaining of calls to set methods
|
|
|
|
- */
|
|
|
|
public Builder setTitle(@StringRes int titleId) {
|
|
public Builder setTitle(@StringRes int titleId) {
|
|
builder.title(titleId);
|
|
builder.title(titleId);
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set the title displayed in the {@link MaterialDialog}.
|
|
|
|
- *
|
|
|
|
- * @return This Builder object to allow for chaining of calls to set methods
|
|
|
|
- */
|
|
|
|
public Builder setTitle(@NonNull CharSequence title) {
|
|
public Builder setTitle(@NonNull CharSequence title) {
|
|
builder.title(title);
|
|
builder.title(title);
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set the resource id of the {@link android.graphics.drawable.Drawable} to be used in the title.
|
|
|
|
- *
|
|
|
|
- * @return This Builder object to allow for chaining of calls to set methods
|
|
|
|
- */
|
|
|
|
public Builder setIcon(@DrawableRes int iconId) {
|
|
public Builder setIcon(@DrawableRes int iconId) {
|
|
builder.icon(iconId);
|
|
builder.icon(iconId);
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set the {@link android.graphics.drawable.Drawable} to be used in the title.
|
|
|
|
- *
|
|
|
|
- * @return This Builder object to allow for chaining of calls to set methods
|
|
|
|
- */
|
|
|
|
public Builder setIcon(Drawable icon) {
|
|
public Builder setIcon(Drawable icon) {
|
|
builder.icon(icon);
|
|
builder.icon(icon);
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set the attribute ID of the {@link android.graphics.drawable.Drawable} to be used in the title (e.g. android.R.attr.dialogicon)
|
|
|
|
- *
|
|
|
|
- * @return This Builder object to allow for chaining of calls to set methods
|
|
|
|
- */
|
|
|
|
public Builder setIconAttribute(@AttrRes int attrId) {
|
|
public Builder setIconAttribute(@AttrRes int attrId) {
|
|
builder.iconAttr(attrId);
|
|
builder.iconAttr(attrId);
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set a listener to be invoked when the negative button of the dialog is pressed.
|
|
|
|
- *
|
|
|
|
- * @param textId The resource id of the text to display in the negative button
|
|
|
|
- * @param listener The {@link DialogInterface.OnClickListener} to use.
|
|
|
|
- * @return This Builder object to allow for chaining of calls to set methods
|
|
|
|
- */
|
|
|
|
public Builder setNegativeButton(@StringRes int textId,
|
|
public Builder setNegativeButton(@StringRes int textId,
|
|
DialogInterface.OnClickListener listener) {
|
|
DialogInterface.OnClickListener listener) {
|
|
builder.negativeText(textId);
|
|
builder.negativeText(textId);
|
|
@@ -128,13 +80,6 @@ public class MaterialDialogCompat {
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set a listener to be invoked when the negative button of the dialog is pressed.
|
|
|
|
- *
|
|
|
|
- * @param text The text to display in the negative button
|
|
|
|
- * @param listener The {@link DialogInterface.OnClickListener} to use.
|
|
|
|
- * @return This Builder object to allow for chaining of calls to set methods
|
|
|
|
- */
|
|
|
|
public Builder setNegativeButton(CharSequence text,
|
|
public Builder setNegativeButton(CharSequence text,
|
|
DialogInterface.OnClickListener listener) {
|
|
DialogInterface.OnClickListener listener) {
|
|
builder.negativeText(text);
|
|
builder.negativeText(text);
|
|
@@ -142,13 +87,6 @@ public class MaterialDialogCompat {
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set a listener to be invoked when the positive button of the dialog is pressed.
|
|
|
|
- *
|
|
|
|
- * @param textId The resource id of the text to display in the positive button
|
|
|
|
- * @param listener The {@link DialogInterface.OnClickListener} to use.
|
|
|
|
- * @return This Builder object to allow for chaining of calls to set methods
|
|
|
|
- */
|
|
|
|
public Builder setPositiveButton(@StringRes int textId,
|
|
public Builder setPositiveButton(@StringRes int textId,
|
|
DialogInterface.OnClickListener listener) {
|
|
DialogInterface.OnClickListener listener) {
|
|
builder.positiveText(textId);
|
|
builder.positiveText(textId);
|
|
@@ -156,13 +94,6 @@ public class MaterialDialogCompat {
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set a listener to be invoked when the positive button of the dialog is pressed.
|
|
|
|
- *
|
|
|
|
- * @param text The text to display in the positive button
|
|
|
|
- * @param listener The {@link DialogInterface.OnClickListener} to use.
|
|
|
|
- * @return This Builder object to allow for chaining of calls to set methods
|
|
|
|
- */
|
|
|
|
public Builder setPositiveButton(CharSequence text,
|
|
public Builder setPositiveButton(CharSequence text,
|
|
DialogInterface.OnClickListener listener) {
|
|
DialogInterface.OnClickListener listener) {
|
|
builder.positiveText(text);
|
|
builder.positiveText(text);
|
|
@@ -170,13 +101,6 @@ public class MaterialDialogCompat {
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set a listener to be invoked when the neutral button of the dialog is pressed.
|
|
|
|
- *
|
|
|
|
- * @param textId The resource id of the text to display in the neutral button
|
|
|
|
- * @param listener The {@link DialogInterface.OnClickListener} to use.
|
|
|
|
- * @return This Builder object to allow for chaining of calls to set methods
|
|
|
|
- */
|
|
|
|
public Builder setNeutralButton(@StringRes int textId,
|
|
public Builder setNeutralButton(@StringRes int textId,
|
|
DialogInterface.OnClickListener listener) {
|
|
DialogInterface.OnClickListener listener) {
|
|
builder.neutralText(textId);
|
|
builder.neutralText(textId);
|
|
@@ -184,13 +108,6 @@ public class MaterialDialogCompat {
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set a listener to be invoked when the neutral button of the dialog is pressed.
|
|
|
|
- *
|
|
|
|
- * @param text The text to display in the neutral button
|
|
|
|
- * @param listener The {@link DialogInterface.OnClickListener} to use.
|
|
|
|
- * @return This Builder object to allow for chaining of calls to set methods
|
|
|
|
- */
|
|
|
|
public Builder setNeutralButton(CharSequence text,
|
|
public Builder setNeutralButton(CharSequence text,
|
|
DialogInterface.OnClickListener listener) {
|
|
DialogInterface.OnClickListener listener) {
|
|
builder.neutralText(text);
|
|
builder.neutralText(text);
|
|
@@ -198,66 +115,34 @@ public class MaterialDialogCompat {
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Sets whether the dialog is cancelable or not. Default is true.
|
|
|
|
- *
|
|
|
|
- * @return This Builder object to allow for chaining of calls to set methods
|
|
|
|
- */
|
|
|
|
public Builder setCancelable(boolean cancelable) {
|
|
public Builder setCancelable(boolean cancelable) {
|
|
builder.cancelable(cancelable);
|
|
builder.cancelable(cancelable);
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set a list of items to be displayed in the dialog as the content, you will be notified of the
|
|
|
|
- * selected item via the supplied listener. This should be an array type i.e. R.array.foo
|
|
|
|
- *
|
|
|
|
- * @return This Builder object to allow for chaining of calls to set methods
|
|
|
|
- */
|
|
|
|
public Builder setItems(int itemsId, final DialogInterface.OnClickListener listener) {
|
|
public Builder setItems(int itemsId, final DialogInterface.OnClickListener listener) {
|
|
builder.items(itemsId);
|
|
builder.items(itemsId);
|
|
onClickListener = listener;
|
|
onClickListener = listener;
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set a list of items to be displayed in the dialog as the content, you will be notified of the
|
|
|
|
- * selected item via the supplied listener.
|
|
|
|
- *
|
|
|
|
- * @return This Builder object to allow for chaining of calls to set methods
|
|
|
|
- */
|
|
|
|
public Builder setItems(CharSequence[] items, DialogInterface.OnClickListener listener) {
|
|
public Builder setItems(CharSequence[] items, DialogInterface.OnClickListener listener) {
|
|
builder.items(items);
|
|
builder.items(items);
|
|
onClickListener = listener;
|
|
onClickListener = listener;
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Sets a custom {@link android.widget.ListAdapter} for the dialog's list
|
|
|
|
- *
|
|
|
|
- * @return This Builder object to allow for chaining of calls to set methods
|
|
|
|
- */
|
|
|
|
public Builder setAdapter(ListAdapter adapter) {
|
|
public Builder setAdapter(ListAdapter adapter) {
|
|
builder.adapter = adapter;
|
|
builder.adapter = adapter;
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Creates a {@link AlertDialog} with the arguments supplied to this builder. It does not
|
|
|
|
- * {@link AlertDialog#show()} the dialog. This allows the user to do any extra processing
|
|
|
|
- * before displaying the dialog. Use {@link #show()} if you don't have any other processing
|
|
|
|
- * to do and want this to be created and displayed.
|
|
|
|
- */
|
|
|
|
public AlertDialog create() {
|
|
public AlertDialog create() {
|
|
addButtonsCallback();
|
|
addButtonsCallback();
|
|
addItemsCallBack();
|
|
addItemsCallBack();
|
|
return builder.build();
|
|
return builder.build();
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Creates a {@link AlertDialog} with the arguments supplied to this builder and
|
|
|
|
- * {@link AlertDialog#show()}'s the dialog.
|
|
|
|
- */
|
|
|
|
public AlertDialog show() {
|
|
public AlertDialog show() {
|
|
AlertDialog dialog = create();
|
|
AlertDialog dialog = create();
|
|
dialog.show();
|
|
dialog.show();
|
|
@@ -302,24 +187,17 @@ public class MaterialDialogCompat {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set a custom view resource to be the contents of the Dialog.
|
|
|
|
- *
|
|
|
|
- * @param view The view to use as the contents of the Dialog.
|
|
|
|
- * @return This
|
|
|
|
- */
|
|
|
|
- public Builder setView(View view) {
|
|
|
|
- boolean wrapInScrollView = !(view instanceof ScrollView || view instanceof AdapterView || view instanceof WebView);
|
|
|
|
- builder.customView(view, wrapInScrollView);
|
|
|
|
- return this;
|
|
|
|
- }
|
|
|
|
|
|
+ public Builder setView(View view) {
|
|
|
|
+ builder.customView(view, false);
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Set a list of items to be displayed in the dialog as the content, you will be notified of the selected item via the supplied listener.
|
|
* Set a list of items to be displayed in the dialog as the content, you will be notified of the selected item via the supplied listener.
|
|
*
|
|
*
|
|
- * @param itemsId A resource ID for the items (e.g. R.array.my_items)
|
|
|
|
- * @param checkedItems specifies which items are checked. It should be null in which case no items are checked. If non null it must be exactly the same length as the array of items.
|
|
|
|
- * @param listener notified when an item on the list is clicked. The dialog will not be dismissed when an item is clicked. It will only be dismissed if clicked on a button, if no buttons are supplied it's up to the user to dismiss the dialog. * @return
|
|
|
|
|
|
+ * @param itemsId A resource ID for the items (e.g. R.array.my_items)
|
|
|
|
+ * @param checkedItems specifies which items are checked. It should be null in which case no items are checked. If non null it must be exactly the same length as the array of items.
|
|
|
|
+ * @param listener notified when an item on the list is clicked. The dialog will not be dismissed when an item is clicked. It will only be dismissed if clicked on a button, if no buttons are supplied it's up to the user to dismiss the dialog. * @return
|
|
* @return This
|
|
* @return This
|
|
*/
|
|
*/
|
|
public Builder setMultiChoiceItems(@ArrayRes int itemsId, @Nullable final boolean[] checkedItems, final DialogInterface.OnMultiChoiceClickListener listener) {
|
|
public Builder setMultiChoiceItems(@ArrayRes int itemsId, @Nullable final boolean[] checkedItems, final DialogInterface.OnMultiChoiceClickListener listener) {
|
|
@@ -328,23 +206,23 @@ public class MaterialDialogCompat {
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set a list of items to be displayed in the dialog as the content, you will be notified of the selected item via the supplied listener.
|
|
|
|
- *
|
|
|
|
- * @param items the text of the items to be displayed in the list.
|
|
|
|
- * @param checkedItems specifies which items are checked. It should be null in which case no items are checked. If non null it must be exactly the same length as the array of items.
|
|
|
|
- * @param listener notified when an item on the list is clicked. The dialog will not be dismissed when an item is clicked. It will only be dismissed if clicked on a button, if no buttons are supplied it's up to the user to dismiss the dialog. * @return
|
|
|
|
- * @return This
|
|
|
|
- */
|
|
|
|
- public Builder setMultiChoiceItems(String[] items, @Nullable final boolean[] checkedItems, final DialogInterface.OnMultiChoiceClickListener listener) {
|
|
|
|
- builder.items(items);
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Set a list of items to be displayed in the dialog as the content, you will be notified of the selected item via the supplied listener.
|
|
|
|
+ *
|
|
|
|
+ * @param items the text of the items to be displayed in the list.
|
|
|
|
+ * @param checkedItems specifies which items are checked. It should be null in which case no items are checked. If non null it must be exactly the same length as the array of items.
|
|
|
|
+ * @param listener notified when an item on the list is clicked. The dialog will not be dismissed when an item is clicked. It will only be dismissed if clicked on a button, if no buttons are supplied it's up to the user to dismiss the dialog. * @return
|
|
|
|
+ * @return This
|
|
|
|
+ */
|
|
|
|
+ public Builder setMultiChoiceItems(String[] items, @Nullable final boolean[] checkedItems, final DialogInterface.OnMultiChoiceClickListener listener) {
|
|
|
|
+ builder.items(items);
|
|
setUpMultiChoiceCallback(checkedItems, listener);
|
|
setUpMultiChoiceCallback(checkedItems, listener);
|
|
- return this;
|
|
|
|
- }
|
|
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
|
|
private void setUpMultiChoiceCallback(@Nullable final boolean[] checkedItems, final DialogInterface.OnMultiChoiceClickListener listener) {
|
|
private void setUpMultiChoiceCallback(@Nullable final boolean[] checkedItems, final DialogInterface.OnMultiChoiceClickListener listener) {
|
|
Integer selectedIndicesArr[] = null;
|
|
Integer selectedIndicesArr[] = null;
|
|
- /* Convert old style array of booleans-per-index to new list of indices */
|
|
|
|
|
|
+ /* Convert old style array of booleans-per-index to new list of indices */
|
|
if (checkedItems != null) {
|
|
if (checkedItems != null) {
|
|
ArrayList<Integer> selectedIndices = new ArrayList<>();
|
|
ArrayList<Integer> selectedIndices = new ArrayList<>();
|
|
for (int i = 0; i < checkedItems.length; i++) {
|
|
for (int i = 0; i < checkedItems.length; i++) {
|
|
@@ -358,16 +236,16 @@ public class MaterialDialogCompat {
|
|
builder.itemsCallbackMultiChoice(selectedIndicesArr, new MaterialDialog.ListCallbackMulti() {
|
|
builder.itemsCallbackMultiChoice(selectedIndicesArr, new MaterialDialog.ListCallbackMulti() {
|
|
@Override
|
|
@Override
|
|
public void onSelection(MaterialDialog dialog, Integer[] which, CharSequence[] text) {
|
|
public void onSelection(MaterialDialog dialog, Integer[] which, CharSequence[] text) {
|
|
- /* which is a list of selected indices */
|
|
|
|
|
|
+ /* which is a list of selected indices */
|
|
List<Integer> whichList = Arrays.asList(which);
|
|
List<Integer> whichList = Arrays.asList(which);
|
|
if (checkedItems != null) {
|
|
if (checkedItems != null) {
|
|
- for(int i = 0; i < checkedItems.length; i++) {
|
|
|
|
|
|
+ for (int i = 0; i < checkedItems.length; i++) {
|
|
/* save old state */
|
|
/* save old state */
|
|
boolean oldChecked = checkedItems[i];
|
|
boolean oldChecked = checkedItems[i];
|
|
/* Record new state */
|
|
/* Record new state */
|
|
checkedItems[i] = whichList.contains(i);
|
|
checkedItems[i] = whichList.contains(i);
|
|
/* Fire the listener if it changed */
|
|
/* Fire the listener if it changed */
|
|
- if(oldChecked != checkedItems[i]) {
|
|
|
|
|
|
+ if (oldChecked != checkedItems[i]) {
|
|
listener.onClick(dialog, i, checkedItems[i]);
|
|
listener.onClick(dialog, i, checkedItems[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -376,43 +254,43 @@ public class MaterialDialogCompat {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set a list of items to be displayed in the dialog as the content, you will be notified of the selected item via the supplied listener.
|
|
|
|
- *
|
|
|
|
- * @param items the items to be displayed.
|
|
|
|
- * @param checkedItem specifies which item is checked. If -1 no items are checked.
|
|
|
|
- * @param listener notified when an item on the list is clicked. The dialog will not be dismissed when an item is clicked. It will only be dismissed if clicked on a button, if no buttons are supplied it's up to the user to dismiss the dialog.
|
|
|
|
- * @return This
|
|
|
|
- */
|
|
|
|
- public Builder setSingleChoiceItems(String[] items, int checkedItem, final DialogInterface.OnClickListener listener) {
|
|
|
|
- builder.items(items);
|
|
|
|
- builder.itemsCallbackSingleChoice(checkedItem, new MaterialDialog.ListCallback() {
|
|
|
|
- @Override
|
|
|
|
- public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
|
|
|
|
- listener.onClick(dialog, which);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- return this;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Set a list of items to be displayed in the dialog as the content, you will be notified of the selected item via the supplied listener.
|
|
|
|
- *
|
|
|
|
- * @param itemsId the resource id of an array i.e. R.array.foo
|
|
|
|
- * @param checkedItem specifies which item is checked. If -1 no items are checked.
|
|
|
|
- * @param listener notified when an item on the list is clicked. The dialog will not be dismissed when an item is clicked. It will only be dismissed if clicked on a button, if no buttons are supplied it's up to the user to dismiss the dialog.
|
|
|
|
- * @return This
|
|
|
|
- */
|
|
|
|
- public Builder setSingleChoiceItems(@ArrayRes int itemsId, int checkedItem, final DialogInterface.OnClickListener listener) {
|
|
|
|
- builder.items(itemsId);
|
|
|
|
- builder.itemsCallbackSingleChoice(checkedItem, new MaterialDialog.ListCallback() {
|
|
|
|
- @Override
|
|
|
|
- public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
|
|
|
|
- listener.onClick(dialog, which);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- return this;
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Set a list of items to be displayed in the dialog as the content, you will be notified of the selected item via the supplied listener.
|
|
|
|
+ *
|
|
|
|
+ * @param items the items to be displayed.
|
|
|
|
+ * @param checkedItem specifies which item is checked. If -1 no items are checked.
|
|
|
|
+ * @param listener notified when an item on the list is clicked. The dialog will not be dismissed when an item is clicked. It will only be dismissed if clicked on a button, if no buttons are supplied it's up to the user to dismiss the dialog.
|
|
|
|
+ * @return This
|
|
|
|
+ */
|
|
|
|
+ public Builder setSingleChoiceItems(String[] items, int checkedItem, final DialogInterface.OnClickListener listener) {
|
|
|
|
+ builder.items(items);
|
|
|
|
+ builder.itemsCallbackSingleChoice(checkedItem, new MaterialDialog.ListCallback() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
|
|
|
|
+ listener.onClick(dialog, which);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Set a list of items to be displayed in the dialog as the content, you will be notified of the selected item via the supplied listener.
|
|
|
|
+ *
|
|
|
|
+ * @param itemsId the resource id of an array i.e. R.array.foo
|
|
|
|
+ * @param checkedItem specifies which item is checked. If -1 no items are checked.
|
|
|
|
+ * @param listener notified when an item on the list is clicked. The dialog will not be dismissed when an item is clicked. It will only be dismissed if clicked on a button, if no buttons are supplied it's up to the user to dismiss the dialog.
|
|
|
|
+ * @return This
|
|
|
|
+ */
|
|
|
|
+ public Builder setSingleChoiceItems(@ArrayRes int itemsId, int checkedItem, final DialogInterface.OnClickListener listener) {
|
|
|
|
+ builder.items(itemsId);
|
|
|
|
+ builder.itemsCallbackSingleChoice(checkedItem, new MaterialDialog.ListCallback() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
|
|
|
|
+ listener.onClick(dialog, which);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
|
|
public Builder setOnCancelListener(DialogInterface.OnCancelListener listener) {
|
|
public Builder setOnCancelListener(DialogInterface.OnCancelListener listener) {
|
|
builder.cancelListener(listener);
|
|
builder.cancelListener(listener);
|
|
@@ -433,5 +311,5 @@ public class MaterialDialogCompat {
|
|
builder.keyListener(listener);
|
|
builder.keyListener(listener);
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|