public final class

CarListDialog.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.car.app.CarListDialog.Builder

Overview

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

Summary

Constructors
publicBuilder(Context context)

Creates a new instance of the Builder.

Methods
public CarListDialogcreate()

Creates an CarListDialog with the arguments supplied to this Builder.

public CarListDialog.BuildersetCancelable(boolean cancelable)

Sets whether the dialog is cancelable or not.

public CarListDialog.BuildersetInitialPosition(int initialPosition)

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

public CarListDialog.BuildersetItems(CarListDialog.DialogSubSection sections[], OnClickListener onClickListener)

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

public CarListDialog.BuildersetItems(java.lang.CharSequence items[], OnClickListener onClickListener)

Sets the items that should appear in the list.

public CarListDialog.BuildersetOnCancelListener(OnCancelListener onCancelListener)

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

public CarListDialog.BuildersetOnDismissListener(OnDismissListener onDismissListener)

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

public CarListDialog.BuildersetTitle(java.lang.CharSequence title)

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

public CarListDialog.BuildersetTitle(int titleId)

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

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder(Context context)

Creates a new instance of the Builder.

Parameters:

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

Methods

public CarListDialog.Builder setTitle(int titleId)

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

Parameters:

titleId: The resource id of the string to be used as the title. Text style will be retained.

Returns:

This Builder object to allow for chaining of calls.

public CarListDialog.Builder setTitle(java.lang.CharSequence title)

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

Parameters:

title: The string to be used as the title.

Returns:

This Builder object to allow for chaining of calls.

public CarListDialog.Builder setItems(java.lang.CharSequence items[], OnClickListener onClickListener)

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 is given, then it will be notified of the click. The dialog will still be dismissed afterwards. The which parameter of the 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 CarListDialog.Builder are called, then the sections will take precedent, and the items set via this method will be ignored.

Parameters:

items: The items that will appear in the list.
onClickListener: The listener that will be notified of a click.

Returns:

This Builder object to allow for chaining of calls.

public CarListDialog.Builder setItems(CarListDialog.DialogSubSection sections[], OnClickListener onClickListener)

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 is given, then it will be notified of the click. The dialog will still be dismissed afterwards. The which parameter of the 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 CarListDialog.Builder.setItems(CharSequence[], OnClickListener) are called, then the sections will take precedent, and the items set via the other method will be ignored.

Parameters:

sections: The sections that will appear in the list.
onClickListener: The listener that will be notified of a click.

Returns:

This Builder object to allow for chaining of calls.

public CarListDialog.Builder setInitialPosition(int initialPosition)

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 CarListDialog.Builder, then note that the title of the section counts as an item in the list.

Parameters:

initialPosition: The initial position in the list to display.

Returns:

This Builder object to allow for chaining of calls.

public CarListDialog.Builder setCancelable(boolean cancelable)

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

Returns:

This Builder object to allow for chaining of calls.

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

Parameters:

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

Returns:

This Builder object to allow for chaining of calls.

See also: CarListDialog.Builder.setCancelable(boolean), CarListDialog.Builder.setOnDismissListener(OnDismissListener)

public CarListDialog.Builder setOnDismissListener(OnDismissListener onDismissListener)

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

Returns:

This Builder object to allow for chaining of calls.

public CarListDialog create()

Creates an CarListDialog with the arguments supplied to this Builder.

If CarListDialog.Builder is never called, then calling this method will throw an exception.

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