CarListDialog.Builder
public
static
final
class
CarListDialog.Builder
extends Object
java.lang.Object | |
↳ | 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 | |
---|---|
CarListDialog.Builder(Context context)
Creates a new instance of the |
Public methods | |
---|---|
CarListDialog
|
create()
Creates an |
CarListDialog.Builder
|
setCancelable(boolean cancelable)
Sets whether the dialog is cancelable or not. |
CarListDialog.Builder
|
setInitialPosition(int initialPosition)
Sets the initial position in the list that the |
CarListDialog.Builder
|
setItems(DialogSubSection[] sections, DialogInterface.OnClickListener onClickListener)
Sets the items that should appear in the list, divided into sections. |
CarListDialog.Builder
|
setItems(CharSequence[] items, DialogInterface.OnClickListener onClickListener)
Sets the items that should appear in the list. |
CarListDialog.Builder
|
setOnCancelListener(DialogInterface.OnCancelListener onCancelListener)
Sets the callback that will be called if the dialog is canceled. |
CarListDialog.Builder
|
setOnDismissListener(DialogInterface.OnDismissListener onDismissListener)
Sets the callback that will be called when the dialog is dismissed for any reason. |
CarListDialog.Builder
|
setTitle(CharSequence title)
Sets the title of the dialog for be the given string. |
CarListDialog.Builder
|
setTitle(int titleId)
Sets the title of the dialog to be the given string resource. |
Inherited methods | |
---|---|
Public constructors
CarListDialog.Builder
public CarListDialog.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 CarListDialog create ()
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
DialogFragment
to show the dialog.
Returns | |
---|---|
CarListDialog |
setCancelable
public CarListDialog.Builder setCancelable (boolean cancelable)
Sets whether the dialog is cancelable or not. Default is true
.
Parameters | |
---|---|
cancelable |
boolean |
Returns | |
---|---|
CarListDialog.Builder |
This Builder object to allow for chaining of calls.
|
setInitialPosition
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
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. |
Returns | |
---|---|
CarListDialog.Builder |
This Builder object to allow for chaining of calls.
|
setItems
public CarListDialog.Builder setItems (DialogSubSection[] sections, DialogInterface.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 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 |
DialogSubSection : The sections that will appear in the list. |
onClickListener |
DialogInterface.OnClickListener : The listener that will be notified of a click. |
Returns | |
---|---|
CarListDialog.Builder |
This Builder object to allow for chaining of calls.
|
setItems
public CarListDialog.Builder setItems (CharSequence[] items, DialogInterface.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 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 |
CharSequence : The items that will appear in the list. |
onClickListener |
DialogInterface.OnClickListener : The listener that will be notified of a click. |
Returns | |
---|---|
CarListDialog.Builder |
This Builder object to allow for chaining of calls.
|
setOnCancelListener
public CarListDialog.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 | |
---|---|
CarListDialog.Builder |
This Builder object to allow for chaining of calls. |
setOnDismissListener
public CarListDialog.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 | |
---|---|
CarListDialog.Builder |
This Builder object to allow for chaining of calls.
|
setTitle
public CarListDialog.Builder setTitle (CharSequence title)
Sets the title of the dialog for be the given string.
Parameters | |
---|---|
title |
CharSequence : The string to be used as the title. |
Returns | |
---|---|
CarListDialog.Builder |
This Builder object to allow for chaining of calls.
|
setTitle
public CarListDialog.Builder setTitle (int titleId)
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. |
Returns | |
---|---|
CarListDialog.Builder |
This Builder object to allow for chaining of calls.
|