belongs to Maven artifact androidx.car:car:1.0.0-alpha4

CarAlertDialog.Builder

public static final class CarAlertDialog.Builder
extends Object

java.lang.Object
   ↳ androidx.car.app.CarAlertDialog.Builder


Builder class that can be used to create a CarAlertDialog by configuring the options for what shows up in the resulting dialog.

Summary

Public constructors

CarAlertDialog.Builder(Context context)

Creates a new instance of the Builder.

Public methods

CarAlertDialog create()

Creates an CarAlertDialog with the arguments supplied to this Builder.

CarAlertDialog.Builder setBody(int bodyId)

Sets the body text of the dialog to be the given string resource.

CarAlertDialog.Builder setBody(CharSequence body)

Sets the body text of the dialog to be the given string.

CarAlertDialog.Builder setCancelable(boolean cancelable)

Sets whether the dialog is cancelable or not.

CarAlertDialog.Builder setNegativeButton(CharSequence text, DialogInterface.OnClickListener listener)

Sets the text of the negative button and the listener that will be invoked when the button is pressed.

CarAlertDialog.Builder setNegativeButton(int textId, DialogInterface.OnClickListener listener)

Sets the text of the negative button and the listener that will be invoked when the button is pressed.

CarAlertDialog.Builder setOnCancelListener(DialogInterface.OnCancelListener onCancelListener)

Sets the callback that will be called if the dialog is canceled.

CarAlertDialog.Builder setOnDismissListener(DialogInterface.OnDismissListener onDismissListener)

Sets the callback that will be called when the dialog is dismissed for any reason.

CarAlertDialog.Builder setPositiveButton(int textId, DialogInterface.OnClickListener listener)

Sets the text of the positive button and the listener that will be invoked when the button is pressed.

CarAlertDialog.Builder setPositiveButton(CharSequence text, DialogInterface.OnClickListener listener)

Sets the text of the positive button and the listener that will be invoked when the button is pressed.

CarAlertDialog.Builder setTitle(CharSequence title)

Sets the main title of the dialog for be the given string.

CarAlertDialog.Builder setTitle(int titleId)

Sets the main title of the dialog to be the given string resource.

Inherited methods

Public constructors

CarAlertDialog.Builder

public CarAlertDialog.Builder (Context context)

Creates a new instance of the Builder.

Parameters
context Context: The Context that the dialog is to be created in.

Public methods

create

public CarAlertDialog create ()

Creates an CarAlertDialog with the arguments supplied to this Builder.

Calling this method does not display the dialog. Utilize this dialog within a DialogFragment to show the dialog.

Returns
CarAlertDialog

setBody

public CarAlertDialog.Builder setBody (int bodyId)

Sets the body text of the dialog to be the given string resource.

Parameters
bodyId int: The resource id of the string to be used as the body text.

Returns
CarAlertDialog.Builder This Builder object to allow for chaining of calls.

setBody

public CarAlertDialog.Builder setBody (CharSequence body)

Sets the body text of the dialog to be the given string.

Parameters
body CharSequence: The string to be used as the body text.

Returns
CarAlertDialog.Builder This Builder object to allow for chaining of calls.

setCancelable

public CarAlertDialog.Builder setCancelable (boolean cancelable)

Sets whether the dialog is cancelable or not. Default is true.

Parameters
cancelable boolean

Returns
CarAlertDialog.Builder This Builder object to allow for chaining of calls.

setNegativeButton

public CarAlertDialog.Builder setNegativeButton (CharSequence text, 
                DialogInterface.OnClickListener listener)

Sets the text of the negative button and the listener that will be invoked when the button is pressed. If a listener is not provided, then the dialog will dismiss itself when the negative button is clicked.

The negative button should be used to cancel any actions the dialog represents.

Parameters
text CharSequence: The string to be used for the negative button text.

listener DialogInterface.OnClickListener: A DialogInterface.OnClickListener to be invoked when the button is clicked. Can be null to represent no listener.

Returns
CarAlertDialog.Builder This Builder object to allow for chaining of calls.

setNegativeButton

public CarAlertDialog.Builder setNegativeButton (int textId, 
                DialogInterface.OnClickListener listener)

Sets the text of the negative button and the listener that will be invoked when the button is pressed. If a listener is not provided, then the dialog will dismiss itself when the negative button is clicked.

The negative button should be used to cancel any actions the dialog represents.

Parameters
textId int: The resource id of the string to be used for the negative button text.

listener DialogInterface.OnClickListener: A DialogInterface.OnClickListener to be invoked when the button is clicked. Can be null to represent no listener.

Returns
CarAlertDialog.Builder This Builder object to allow for chaining of calls.

setOnCancelListener

public CarAlertDialog.Builder setOnCancelListener (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(OnDismissListener).

Parameters
onCancelListener DialogInterface.OnCancelListener: The listener to be invoked when this dialog is canceled.

Returns
CarAlertDialog.Builder This Builder object to allow for chaining of calls.

setOnDismissListener

public CarAlertDialog.Builder setOnDismissListener (DialogInterface.OnDismissListener onDismissListener)

Sets the callback that will be called when the dialog is dismissed for any reason.

Parameters
onDismissListener DialogInterface.OnDismissListener

Returns
CarAlertDialog.Builder This Builder object to allow for chaining of calls.

setPositiveButton

public CarAlertDialog.Builder setPositiveButton (int textId, 
                DialogInterface.OnClickListener listener)

Sets the text of the positive button and the listener that will be invoked when the button is pressed. If a listener is not provided, then the dialog will dismiss itself when the positive button is clicked.

The positive button should be used to accept and continue with the action (e.g. an "OK" action).

Parameters
textId int: The resource id of the string to be used for the positive button text.

listener DialogInterface.OnClickListener: A DialogInterface.OnClickListener to be invoked when the button is clicked. Can be null to represent no listener.

Returns
CarAlertDialog.Builder This Builder object to allow for chaining of calls.

setPositiveButton

public CarAlertDialog.Builder setPositiveButton (CharSequence text, 
                DialogInterface.OnClickListener listener)

Sets the text of the positive button and the listener that will be invoked when the button is pressed. If a listener is not provided, then the dialog will dismiss itself when the positive button is clicked.

The positive button should be used to accept and continue with the action (e.g. an "OK" action).

Parameters
text CharSequence: The string to be used for the positive button text.

listener DialogInterface.OnClickListener: A DialogInterface.OnClickListener to be invoked when the button is clicked. Can be null to represent no listener.

Returns
CarAlertDialog.Builder This Builder object to allow for chaining of calls.

setTitle

public CarAlertDialog.Builder setTitle (CharSequence title)

Sets the main title of the dialog for be the given string.

Parameters
title CharSequence: The string to be used as the title.

Returns
CarAlertDialog.Builder This Builder object to allow for chaining of calls.

setTitle

public CarAlertDialog.Builder setTitle (int titleId)

Sets the main title of the dialog to be the given string resource.

Parameters
titleId int: The resource id of the string to be used as the title.

Returns
CarAlertDialog.Builder This Builder object to allow for chaining of calls.