Builder

class Builder
kotlin.Any
   ↳ androidx.car.app.CarListDialog.Builder

Builder class that can be used to create a CarListDialog by configuring the options for the list and behavior of the dialog.

Summary

Public constructors
<init>(context: Context!)

Creates a new instance of the Builder.

Public methods
CarListDialog!

Creates an CarListDialog with the arguments supplied to this Builder.

CarListDialog.Builder
setCancelable(cancelable: Boolean)

Sets whether the dialog is cancelable or not.

CarListDialog.Builder
setInitialPosition(initialPosition: Int)

Sets the initial position in the list that the CarListDialog will start at.

CarListDialog.Builder
setItems(@NonNull items: Array<CharSequence!>, @Nullable onClickListener: OnClickListener?)

Sets the items that should appear in the list.

CarListDialog.Builder
setItems(@NonNull sections: Array<CarListDialog.DialogSubSection!>, @Nullable onClickListener: OnClickListener?)

Sets the items that should appear in the list, divided into sections.

CarListDialog.Builder

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

CarListDialog.Builder

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

CarListDialog.Builder
setTitle(@StringRes titleId: Int)

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

CarListDialog.Builder

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

Public constructors

<init>

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

fun create(): CarListDialog!

Creates an CarListDialog with the arguments supplied to this Builder.

If setItems(CharSequence[],DialogInterface.OnClickListener) is never called, then calling this method will throw an exception.

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

setCancelable

@NonNull fun setCancelable(cancelable: Boolean): CarListDialog.Builder

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

Return
CarListDialog.Builder: This Builder object to allow for chaining of calls.

setInitialPosition

@NonNull fun setInitialPosition(initialPosition: Int): CarListDialog.Builder

Sets the initial position in the list that the CarListDialog will start at. When the dialog is created, the list will animate to the given position.

The position uses zero-based indexing. So, to scroll to the fifth item in the list, a value of four should be passed.

If the items in this dialog was set by setItems(DialogSubSection[], OnClickListener), then note that the title of the section counts as an item in the list.

Parameters
initialPosition Int: The initial position in the list to display.
Return
CarListDialog.Builder: This Builder object to allow for chaining of calls.

setItems

@NonNull fun setItems(@NonNull items: Array<CharSequence!>, @Nullable onClickListener: OnClickListener?): CarListDialog.Builder

Sets the items that should appear in the list. The dialog will automatically dismiss itself when an item in the list is clicked on.

If a DialogInterface.OnClickListener is given, then it will be notified of the click. The dialog will still be dismissed afterwards. The which parameter of the DialogInterface.OnClickListener#onClick(DialogInterface, int) method will be the position of the item. This position maps to the index of the item in the given list.

The provided list of items cannot be null or empty. Passing an empty list to this method will throw can exception.

If both this method and setItems(DialogSubSection[], OnClickListener) are called, then the sections will take precedent, and the items set via this method will be ignored.

Parameters
items Array<CharSequence!>: The items that will appear in the list.
onClickListener Array<CharSequence!>: The listener that will be notified of a click.
Return
CarListDialog.Builder: This Builder object to allow for chaining of calls.

setItems

@NonNull fun setItems(@NonNull sections: Array<CarListDialog.DialogSubSection!>, @Nullable onClickListener: OnClickListener?): CarListDialog.Builder

Sets the items that should appear in the list, divided into sections. Each section has a title and a list of items associated with it. The dialog will automatically dismiss itself when an item in the list is clicked on; the title of the section is not clickable.

If a DialogInterface.OnClickListener is given, then it will be notified of the click. The dialog will still be dismissed afterwards. The which parameter of the DialogInterface.OnClickListener#onClick(DialogInterface, int) method will be the position of the item. This position maps to the index of the item in the given list.

The provided list of sections cannot be null or empty. The list of items within a section also cannot be empty. Passing an empty list to this method will throw can exception.

If both this method and setItems(CharSequence[], OnClickListener) are called, then the sections will take precedent, and the items set via the other method will be ignored.

Parameters
sections Array<CarListDialog.DialogSubSection!>: The sections that will appear in the list.
onClickListener Array<CarListDialog.DialogSubSection!>: The listener that will be notified of a click.
Return
CarListDialog.Builder: This Builder object to allow for chaining of calls.

setOnCancelListener

@NonNull fun setOnCancelListener(onCancelListener: OnCancelListener!): CarListDialog.Builder

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 OnCancelListener!: The listener to be invoked when this dialog is canceled.
Return
CarListDialog.Builder: This Builder object to allow for chaining of calls.

setOnDismissListener

@NonNull fun setOnDismissListener(onDismissListener: OnDismissListener!): CarListDialog.Builder

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

Return
CarListDialog.Builder: This Builder object to allow for chaining of calls.

setTitle

@NonNull fun setTitle(@StringRes titleId: Int): CarListDialog.Builder

Sets the 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. Text style will be retained.
Return
CarListDialog.Builder: This Builder object to allow for chaining of calls.

setTitle

@NonNull fun setTitle(title: CharSequence!): CarListDialog.Builder

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

Parameters
title CharSequence!: The string to be used as the title.
Return
CarListDialog.Builder: This Builder object to allow for chaining of calls.