Class DynamicDialog.Builder
- Enclosing class:
- DynamicDialog
-
Constructor Summary
ConstructorDescriptionCreates a builder for an alert dialog that uses the default alert dialog theme.Creates a builder for an alert dialog that uses an explicit theme resource.Builder
(Context context, DynamicDialog.Builder builder) Copy constructor to create a builder for another builder. -
Method Summary
Modifier and TypeMethodDescriptioncreate()
Creates anDynamicDialog
with the arguments supplied to this builder.Returns aContext
with the appropriate theme for dialogs created by this Builder.setAdapter
(ListAdapter adapter, DialogInterface.OnClickListener listener) Set a list of items, which are supplied by the givenListAdapter
, to be displayed in the dialog as the content, you will be notified of the selected item via the supplied listener.setCancelable
(boolean cancelable) Sets whether the dialog is cancelable or not.setCursor
(Cursor cursor, DialogInterface.OnClickListener listener, String labelColumn) Set a list of items, which are supplied by the givenCursor
, to be displayed in the dialog as the content, you will be notified of the selected item via the supplied listener.setCustomTitle
(View customTitleView) Set the title using the custom viewcustomTitleView
.setIcon
(int iconId) Set the resource id of theDrawable
to be used in the title.Set theDrawable
to be used in the title.setIconAttribute
(int attrId) Set an icon as supplied by a theme attribute.setInverseBackgroundForced
(boolean useInverseBackground) Deprecated.This flag is only used for pre-Material themes.setItems
(int itemsId, DialogInterface.OnClickListener 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.setItems
(CharSequence[] items, DialogInterface.OnClickListener 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.setMessage
(int messageId) Set the message to display using the given resource id.setMessage
(CharSequence message) Set the message to display.setMultiChoiceItems
(int itemsId, boolean[] checkedItems, DialogInterface.OnMultiChoiceClickListener 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.setMultiChoiceItems
(Cursor cursor, String isCheckedColumn, String labelColumn, DialogInterface.OnMultiChoiceClickListener 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.setMultiChoiceItems
(CharSequence[] items, boolean[] checkedItems, DialogInterface.OnMultiChoiceClickListener 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.setNegativeButton
(int textId, DialogInterface.OnClickListener listener) Set a listener to be invoked when the negative button of the dialog is pressed.setNegativeButton
(CharSequence text, DialogInterface.OnClickListener listener) Set a listener to be invoked when the negative button of the dialog is pressed.Set an icon to be displayed for the negative button.setNeutralButton
(int textId, DialogInterface.OnClickListener listener) Set a listener to be invoked when the neutral button of the dialog is pressed.setNeutralButton
(CharSequence text, DialogInterface.OnClickListener listener) Set a listener to be invoked when the neutral button of the dialog is pressed.setNeutralButtonIcon
(Drawable icon) Set an icon to be displayed for the neutral button.setOnCancelListener
(DialogInterface.OnCancelListener onCancelListener) Sets the callback that will be called if the dialog is canceled.setOnDismissListener
(DialogInterface.OnDismissListener onDismissListener) Sets the callback that will be called when the dialog is dismissed for any reason.Sets a listener to be invoked when an item in the list is selected.setOnKeyListener
(DialogInterface.OnKeyListener onKeyListener) Sets the callback that will be called if a key is dispatched to the dialog.setPositiveButton
(int textId, DialogInterface.OnClickListener listener) Set a listener to be invoked when the positive button of the dialog is pressed.setPositiveButton
(CharSequence text, DialogInterface.OnClickListener listener) Set a listener to be invoked when the positive button of the dialog is pressed.Set an icon to be displayed for the positive button.setRecycleOnMeasureEnabled
(boolean enabled) Set whether to enable recycle on enabled fo the dialog.setSingleChoiceItems
(int itemsId, int checkedItem, DialogInterface.OnClickListener 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.setSingleChoiceItems
(Cursor cursor, int checkedItem, String labelColumn, DialogInterface.OnClickListener 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.setSingleChoiceItems
(ListAdapter adapter, int checkedItem, DialogInterface.OnClickListener 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.setSingleChoiceItems
(CharSequence[] items, int checkedItem, DialogInterface.OnClickListener 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.setTitle
(int titleId) Set the title using the given resource id.setTitle
(CharSequence title) Set the title displayed in theDialog
.setView
(int layoutResId) Set a custom view resource to be the contents of the Dialog.Sets a custom view to be the contents of the alert dialog.setViewRoot
(int viewRootId) Set the view root id to add scroll indicators if the content can be scrolled.setViewRoot
(View viewRoot) Set the view root to add scroll indicators if the content can be scrolled.show()
Creates anDynamicDialog
with the arguments supplied to this builder and immediately displays the dialog.
-
Constructor Details
-
Builder
Creates a builder for an alert dialog that uses the default alert dialog theme.The default alert dialog theme is defined by
R.attr.alertDialogTheme
within the parentcontext
's theme.- Parameters:
context
- the parent context
-
Builder
Creates a builder for an alert dialog that uses an explicit theme resource.The specified theme resource (
themeResId
) is applied on top of the parentcontext
's theme. It may be specified as a style resource containing a fully-populated theme, such asR.style.Theme_AppCompat_Dialog
, to replace all attributes in the parentcontext
's theme including primary and accent colors.To preserve attributes such as primary and accent colors, the
themeResId
may instead be specified as an overlay theme such asR.style.ThemeOverlay_AppCompat_Dialog
. This will override only the window attributes necessary to style the alert window as a dialog.Alternatively, the
themeResId
may be specified as0
to use the parentcontext
's resolved value forR.attr.alertDialogTheme
.- Parameters:
context
- the parent contextthemeResId
- the resource ID of the theme against which to inflate this dialog, or0
to use the parentcontext
's default alert dialog theme
-
Method Details
-
getContext
Returns aContext
with the appropriate theme for dialogs created by this Builder. Applications should use this Context for obtaining LayoutInflaters for inflating views that will be used in the resulting dialogs, as it will cause views to be inflated with the correct theme.- Returns:
- A Context for built Dialogs.
-
setTitle
Set the title using the given resource id.- Parameters:
titleId
- The resource id to display the title.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setTitle
Set the title displayed in theDialog
.- Parameters:
title
- The title to be displayed.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setCustomTitle
Set the title using the custom viewcustomTitleView
.The methods
setTitle(int)
andsetIcon(int)
should be sufficient for most titles, but this is provided if the title needs more customization. Using this will replace the title and icon set via the other methods.Note: To ensure consistent styling, the custom view should be inflated or constructed using the alert dialog's themed context obtained via
getContext()
.- Parameters:
customTitleView
- the custom view to use as the title.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setMessage
Set the message to display using the given resource id.- Parameters:
messageId
- The resource id to display message.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setMessage
Set the message to display.- Parameters:
message
- The message to display.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setIcon
Set the resource id of theDrawable
to be used in the title.Takes precedence over values set using
setIcon(Drawable)
.- Parameters:
iconId
- The resource id to display the drawable.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setIcon
Set theDrawable
to be used in the title.Note: To ensure consistent styling, the drawable should be inflated or constructed using the alert dialog's themed context obtained via
getContext()
.- Parameters:
icon
- The drawable to be used in the title.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setIconAttribute
Set an icon as supplied by a theme attribute. e.g.R.attr.alertDialogIcon
.Takes precedence over values set using
setIcon(int)
orsetIcon(Drawable)
.- Parameters:
attrId
- ID of a theme attribute that points to a drawable resource.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setPositiveButton
public DynamicDialog.Builder setPositiveButton(@StringRes int textId, @Nullable DialogInterface.OnClickListener listener) Set a listener to be invoked when the positive button of the dialog is pressed.- Parameters:
textId
- The resource id of the text to display in the positive button.listener
- TheDialogInterface.OnClickListener
to use.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setPositiveButton
public DynamicDialog.Builder setPositiveButton(@Nullable CharSequence text, @Nullable DialogInterface.OnClickListener listener) Set a listener to be invoked when the positive button of the dialog is pressed.- Parameters:
text
- The text to display in the positive button.listener
- TheDialogInterface.OnClickListener
to use.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setPositiveButtonIcon
Set an icon to be displayed for the positive button.- Parameters:
icon
- The icon to be displayed.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setNegativeButton
public DynamicDialog.Builder setNegativeButton(@StringRes int textId, @Nullable DialogInterface.OnClickListener listener) Set a listener to be invoked when the negative button of the dialog is pressed.- Parameters:
textId
- The resource id of the text to display in the negative button.listener
- TheDialogInterface.OnClickListener
to use.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setNegativeButton
public DynamicDialog.Builder setNegativeButton(@Nullable CharSequence text, @Nullable DialogInterface.OnClickListener listener) Set a listener to be invoked when the negative button of the dialog is pressed.- Parameters:
text
- The text to display in the negative button.listener
- TheDialogInterface.OnClickListener
to use.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setNegativeButtonIcon
Set an icon to be displayed for the negative button.- Parameters:
icon
- The icon to be displayed.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setNeutralButton
public DynamicDialog.Builder setNeutralButton(@StringRes int textId, @Nullable DialogInterface.OnClickListener listener) Set a listener to be invoked when the neutral button of the dialog is pressed.- Parameters:
textId
- The resource id of the text to display in the neutral button.listener
- TheDialogInterface.OnClickListener
to use.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setNeutralButton
public DynamicDialog.Builder setNeutralButton(@Nullable CharSequence text, @Nullable DialogInterface.OnClickListener listener) Set a listener to be invoked when the neutral button of the dialog is pressed.- Parameters:
text
- The text to display in the neutral button.listener
- TheDialogInterface.OnClickListener
to use.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setNeutralButtonIcon
Set an icon to be displayed for the neutral button.- Parameters:
icon
- The icon to be displayed.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setCancelable
Sets whether the dialog is cancelable or not. Default is true.- Parameters:
cancelable
-true
to set the dialog cancelable.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setOnCancelListener
public DynamicDialog.Builder setOnCancelListener(@Nullable DialogInterface.OnCancelListener onCancelListener) Sets the callback that will be called if the dialog is canceled.Even in a cancelable dialog, the dialog may be dismissed for reasons other than being canceled or one of the supplied choices being selected. If you are interested in listening for all cases where the dialog is dismissed and not just when it is canceled, see
setOnDismissListener
.- Parameters:
onCancelListener
- The callback to be set.- Returns:
- This Builder object to allow for chaining of calls to set methods.
- See Also:
-
setOnDismissListener
public DynamicDialog.Builder setOnDismissListener(@Nullable DialogInterface.OnDismissListener onDismissListener) Sets the callback that will be called when the dialog is dismissed for any reason.- Parameters:
onDismissListener
- The callback to be set.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setOnKeyListener
public DynamicDialog.Builder setOnKeyListener(@Nullable DialogInterface.OnKeyListener onKeyListener) Sets the callback that will be called if a key is dispatched to the dialog.- Parameters:
onKeyListener
- The callback to be set.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setItems
public DynamicDialog.Builder setItems(@ArrayRes int itemsId, @Nullable DialogInterface.OnClickListener 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. This should be an array type i.e. R.array.foo- Parameters:
itemsId
- The resource id for the items array.listener
- The click listener to be set.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setItems
public DynamicDialog.Builder setItems(@Nullable CharSequence[] items, @Nullable DialogInterface.OnClickListener 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.- Parameters:
items
- The items array to be displayed.listener
- The click listener to be set.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setAdapter
public DynamicDialog.Builder setAdapter(@Nullable ListAdapter adapter, @Nullable DialogInterface.OnClickListener listener) Set a list of items, which are supplied by the givenListAdapter
, to be displayed in the dialog as the content, you will be notified of the selected item via the supplied listener.- Parameters:
adapter
- TheListAdapter
to supply the list of items.listener
- The listener that will be called when an item is clicked.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setCursor
public DynamicDialog.Builder setCursor(@Nullable Cursor cursor, @Nullable DialogInterface.OnClickListener listener, @Nullable String labelColumn) Set a list of items, which are supplied by the givenCursor
, to be displayed in the dialog as the content, you will be notified of the selected item via the supplied listener.- Parameters:
cursor
- TheCursor
to supply the list of items.listener
- The listener that will be called when an item is clicked.labelColumn
- The column name on the cursor containing the string to display in the label.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setMultiChoiceItems
public DynamicDialog.Builder setMultiChoiceItems(@ArrayRes int itemsId, @Nullable boolean[] checkedItems, @Nullable DialogInterface.OnMultiChoiceClickListener 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. This should be an array type, e.g. R.array.foo. The list will have a check mark displayed to the right of the text for each checked item. Clicking on an item in the list will not dismiss the dialog. Clicking on a button will dismiss the dialog.- Parameters:
itemsId
- the resource id of an array i.e. R.array.foocheckedItems
- 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.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.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setMultiChoiceItems
public DynamicDialog.Builder setMultiChoiceItems(@Nullable CharSequence[] items, @Nullable boolean[] checkedItems, @Nullable DialogInterface.OnMultiChoiceClickListener 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. The list will have a check mark displayed to the right of the text for each checked item. Clicking on an item in the list will not dismiss the dialog. Clicking on a button will dismiss the dialog.- Parameters:
items
- the text of the items to be displayed in the list.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.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.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setMultiChoiceItems
public DynamicDialog.Builder setMultiChoiceItems(@Nullable Cursor cursor, @Nullable String isCheckedColumn, @Nullable String labelColumn, @Nullable DialogInterface.OnMultiChoiceClickListener 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. The list will have a check mark displayed to the right of the text for each checked item. Clicking on an item in the list will not dismiss the dialog. Clicking on a button will dismiss the dialog.- Parameters:
cursor
- the cursor used to provide the items.isCheckedColumn
- specifies the column name on the cursor to use to determine whether a checkbox is checked or not. It must return an integer value where 1 means checked and 0 means unchecked.labelColumn
- The column name on the cursor containing the string to display in the label.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.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setSingleChoiceItems
public DynamicDialog.Builder setSingleChoiceItems(@ArrayRes int itemsId, int checkedItem, @Nullable DialogInterface.OnClickListener 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. This should be an array type i.e. R.array.foo The list will have a check mark displayed to the right of the text for the checked item. Clicking on an item in the list will not dismiss the dialog. Clicking on a button will dismiss the dialog.- Parameters:
itemsId
- the resource id of an array i.e. R.array.foocheckedItem
- specifies which item is checked. If -1 no items are checked.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.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setSingleChoiceItems
public DynamicDialog.Builder setSingleChoiceItems(@Nullable Cursor cursor, int checkedItem, @Nullable String labelColumn, @Nullable DialogInterface.OnClickListener 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. The list will have a check mark displayed to the right of the text for the checked item. Clicking on an item in the list will not dismiss the dialog. Clicking on a button will dismiss the dialog.- Parameters:
cursor
- the cursor to retrieve the items from.checkedItem
- specifies which item is checked. If -1 no items are checked.labelColumn
- The column name on the cursor containing the string to display in the label.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.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setSingleChoiceItems
public DynamicDialog.Builder setSingleChoiceItems(@Nullable CharSequence[] items, int checkedItem, @Nullable DialogInterface.OnClickListener 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. The list will have a check mark displayed to the right of the text for the checked item. Clicking on an item in the list will not dismiss the dialog. Clicking on a button will dismiss the dialog.- Parameters:
items
- the items to be displayed.checkedItem
- specifies which item is checked. If -1 no items are checked.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.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setSingleChoiceItems
public DynamicDialog.Builder setSingleChoiceItems(@Nullable ListAdapter adapter, int checkedItem, @Nullable DialogInterface.OnClickListener 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. The list will have a check mark displayed to the right of the text for the checked item. Clicking on an item in the list will not dismiss the dialog. Clicking on a button will dismiss the dialog.- Parameters:
adapter
- TheListAdapter
to supply the list of items.checkedItem
- specifies which item is checked. If -1 no items are checked.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.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setOnItemSelectedListener
public DynamicDialog.Builder setOnItemSelectedListener(@Nullable AdapterView.OnItemSelectedListener listener) Sets a listener to be invoked when an item in the list is selected.- Parameters:
listener
- the listener to be invoked.- Returns:
- This Builder object to allow for chaining of calls to set methods.
- See Also:
-
setView
Set a custom view resource to be the contents of the Dialog. The resource will be inflated, adding all top-level views to the screen.- Parameters:
layoutResId
- Resource ID to be inflated.- Returns:
- this Builder object to allow for chaining of calls to set methods
-
setView
Sets a custom view to be the contents of the alert dialog.When using a pre-Holo theme, if the supplied view is an instance of a
ListView
then the light background will be used.Note: To ensure consistent styling, the custom view should be inflated or constructed using the alert dialog's themed context obtained via
getContext()
.- Parameters:
view
- the view to use as the contents of the alert dialog- Returns:
- this Builder object to allow for chaining of calls to set methods
-
setViewRoot
Set the view root id to add scroll indicators if the content can be scrolled.- Parameters:
viewRootId
- The root view id of the custom view.- Returns:
- this Builder object to allow for chaining of calls to set methods
-
setViewRoot
Set the view root to add scroll indicators if the content can be scrolled.- Parameters:
viewRoot
- The root view of the custom view.- Returns:
- this Builder object to allow for chaining of calls to set methods
-
setInverseBackgroundForced
Deprecated.This flag is only used for pre-Material themes. Instead, specify the window background using on the alert dialog theme.Sets the Dialog to use the inverse background, regardless of what the contents is.- Parameters:
useInverseBackground
- Whether to use the inverse background- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
setRecycleOnMeasureEnabled
Set whether to enable recycle on enabled fo the dialog.- Parameters:
enabled
-true
to enable the recycle on measure.- Returns:
- This Builder object to allow for chaining of calls to set methods.
-
create
Creates anDynamicDialog
with the arguments supplied to this builder.Calling this method does not display the dialog. If no additional processing is needed,
show()
may be called instead to both create and display the dialog.- Returns:
- The
DynamicDialog
with the arguments supplied to this builder.
-
show
Creates anDynamicDialog
with the arguments supplied to this builder and immediately displays the dialog.Calling this method is functionally identical to:
DynamicDialog dialog = builder.create(); dialog.show();
- Returns:
- The
DynamicDialog
with the arguments supplied to this builder.
-