public class SingleModalChoiceMode extends ObservableChoiceMode
ChoiceMode that allows up to one choice in a modal selection mode.| Constructor and Description |
|---|
SingleModalChoiceMode(ActionModeCompat actionModeCompat,
ModalChoiceModeListener listener) |
SingleModalChoiceMode(ActionModeCompat actionModeCompat,
ModalChoiceModeListener listener,
Bundle savedInstanceState) |
| Modifier and Type | Method and Description |
|---|---|
void |
clearChoices()
Clears any checked items.
|
void |
finish()
Finish and close this action mode.
|
long |
getCheckedItem()
Returns an identifier of checked item or
RecyclerView#NO_ID if no item is checked. |
int |
getCheckedItemCount()
Returns the number of items currently selected.
|
boolean |
isActivated()
Returns true if choice mode is active.
|
boolean |
isItemChecked(long itemId)
Returns the checked state of the specified position.
|
boolean |
onClick(long itemId)
Dispatches click on a specific item.
|
boolean |
onLongClick(long itemId)
Dispatches long click on a specific item.
|
void |
onSaveInstanceState(Bundle outState)
Call this method to retrieve per-instance state before UI component being killed
so that the state can be restored via constructor.
|
void |
registerChoiceModeObserver(ChoiceModeObserver observer)
Register a new observer to listen for selection changes.
|
boolean |
requiresLongpress()
Returns whether long press is required by this choice mode.
|
boolean |
requiresStableIds()
Returns whether stable item ids are required by this choice mode.
|
void |
setFinishActionModeOnClearEnabled(boolean enabled)
Allows action mode be opened when no items are checked.
|
void |
setItemChecked(long itemId,
boolean checked)
Sets the checked state of the specified position.
|
void |
setStartOnSingleTapEnabled(boolean enabled)
Allows to start modal choice on single tap.
|
void |
unregisterChoiceModeObserver(ChoiceModeObserver observer)
Unregister an observer currently listening for selection changes.
|
isAttached, notifyAllItemsCheckedChanged, notifyItemCheckedChangedpublic SingleModalChoiceMode(@NonNull ActionModeCompat actionModeCompat, @NonNull ModalChoiceModeListener listener)
public SingleModalChoiceMode(@NonNull ActionModeCompat actionModeCompat, @NonNull ModalChoiceModeListener listener, @Nullable Bundle savedInstanceState)
public void setStartOnSingleTapEnabled(boolean enabled)
public void setFinishActionModeOnClearEnabled(boolean enabled)
public boolean requiresStableIds()
public boolean requiresLongpress()
public boolean isActivated()
public int getCheckedItemCount()
To determine the specific items that are currently selected, use one of
the getChecked* methods.
public boolean isItemChecked(long itemId)
itemId - The item whose checked state to return.false.public void setItemChecked(long itemId,
boolean checked)
itemId - The item id whose checked state is to be checked.checked - The new checked state for the item.public long getCheckedItem()
RecyclerView#NO_ID if no item is checked.public void clearChoices()
public boolean onClick(long itemId)
ChoiceModeitemId - The item id which has been clicked.public boolean onLongClick(long itemId)
ChoiceModeitemId - The item id which has been clicked.public void registerChoiceModeObserver(@NonNull ChoiceModeObserver observer)
The choice mode may publish a variety of events describing selection changes.
Components registering observers with a choice mode are responsible for
ChoiceMode.unregisterChoiceModeObserver(ChoiceModeObserver)
unregistering} those observers when finished.
registerChoiceModeObserver in interface ChoiceModeregisterChoiceModeObserver in class ObservableChoiceModeobserver - Observer to register.ChoiceMode.unregisterChoiceModeObserver(ChoiceModeObserver)public void unregisterChoiceModeObserver(@NonNull ChoiceModeObserver observer)
The unregistered observer will no longer receive events about changes to the choice mode.
unregisterChoiceModeObserver in interface ChoiceModeunregisterChoiceModeObserver in class ObservableChoiceModeobserver - Observer to unregister.ChoiceMode.registerChoiceModeObserver(ChoiceModeObserver)public void finish()
ModalChoiceModeListener will
have its ModalChoiceModeListener#onDestroyActionMode(ActionMode) method called.