{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}
public final class RecyclerViewActions
ViewActions to interact RecyclerView. RecyclerView works differently than . In fact, RecyclerView is not an AdapterView anymore, hence it can't be used in combination with onData.
To use ViewActions in this class use onView with a Matcher
that matches your RecyclerView, then perform a ViewAction from this class.
Nested types |
|
|---|---|
RecyclerViewActions.PositionableRecyclerViewAction |
Most RecyclerViewActions are given a matcher to select a particular view / viewholder within the RecyclerView. |
Public constructors |
|
|---|---|
Public methods |
|
|---|---|
static RecyclerViewActions.PositionableRecyclerViewAction |
<VH extends RecyclerView.ViewHolder> actionOnHolderItem(Performs a |
static RecyclerViewActions.PositionableRecyclerViewAction |
<VH extends RecyclerView.ViewHolder> actionOnItem(Performs a |
static ViewAction |
<VH extends RecyclerView.ViewHolder> actionOnItemAtPosition(Performs a |
static RecyclerViewActions.PositionableRecyclerViewAction |
<VH extends RecyclerView.ViewHolder> scrollTo(Matcher<View> itemViewMatcher)Returns a |
static RecyclerViewActions.PositionableRecyclerViewAction |
<VH extends RecyclerView.ViewHolder> scrollToHolder(Returns a |
static @NonNull ViewAction |
<VH extends RecyclerView.ViewHolder> scrollToLastPosition()Returns a |
static ViewAction |
<VH extends RecyclerView.ViewHolder> scrollToPosition(int position)Returns a |
public static RecyclerViewActions.PositionableRecyclerViewAction <VH extends RecyclerView.ViewHolder> actionOnHolderItem(
Matcher<VH> viewHolderMatcher,
ViewAction viewAction
)
Performs a ViewAction on a view matched by viewHolderMatcher.
| Parameters | |
|---|---|
Matcher<VH> viewHolderMatcher |
a |
ViewAction viewAction |
the action that is performed on the view matched by viewHolderMatcher |
| Throws | |
|---|---|
androidx.test.espresso.PerformException androidx.test.espresso.PerformException |
if there are more than one items matching given viewHolderMatcher. |
public static RecyclerViewActions.PositionableRecyclerViewAction <VH extends RecyclerView.ViewHolder> actionOnItem(
Matcher<View> itemViewMatcher,
ViewAction viewAction
)
Performs a ViewAction on a view matched by viewHolderMatcher.
| Parameters | |
|---|---|
Matcher<View> itemViewMatcher |
a |
ViewAction viewAction |
the action that is performed on the view matched by itemViewMatcher |
| Throws | |
|---|---|
androidx.test.espresso.PerformException androidx.test.espresso.PerformException |
if there are more than one items matching given viewHolderMatcher. |
public static ViewAction <VH extends RecyclerView.ViewHolder> actionOnItemAtPosition(
int position,
ViewAction viewAction
)
Performs a ViewAction on a view at position.
| Parameters | |
|---|---|
int position |
position of a view in |
ViewAction viewAction |
the action that is performed on the view matched by itemViewMatcher |
public static RecyclerViewActions.PositionableRecyclerViewAction <VH extends RecyclerView.ViewHolder> scrollTo(Matcher<View> itemViewMatcher)
Returns a ViewAction which scrolls RecyclerView to the view matched by itemViewMatcher.
This approach uses ViewHolders to find the target view. It will create one ViewHolder per item type and bind adapter data to the ViewHolder. If the itemViewMatcher matches a ViewHolder the current position of the View is used to perform a scrollToPosition.
| Parameters | |
|---|---|
Matcher<View> itemViewMatcher |
a |
| Throws | |
|---|---|
androidx.test.espresso.PerformException androidx.test.espresso.PerformException |
if there are more than one items matching given viewHolderMatcher. |
public static RecyclerViewActions.PositionableRecyclerViewAction <VH extends RecyclerView.ViewHolder> scrollToHolder(
Matcher<VH> viewHolderMatcher
)
Returns a ViewAction which scrolls RecyclerView to the view matched by viewHolderMatcher.
This approach uses ViewHolders to find the target view. It will create one ViewHolder per item type and bind adapter data to the ViewHolder. If the itemViewMatcher matches a ViewHolder the current position of the View is used to perform a scrollToPosition. Note: scrollTo method is not overloaded, method overloading with generic parameters is not possible.
| Parameters | |
|---|---|
Matcher<VH> viewHolderMatcher |
a |
| Throws | |
|---|---|
androidx.test.espresso.PerformException androidx.test.espresso.PerformException |
if there are more than one items matching given viewHolderMatcher. |
public static @NonNull ViewAction <VH extends RecyclerView.ViewHolder> scrollToLastPosition()
Returns a ViewAction which scrolls RecyclerView to the last position.
public static ViewAction <VH extends RecyclerView.ViewHolder> scrollToPosition(int position)
Returns a ViewAction which scrolls RecyclerView to a position.
| Parameters | |
|---|---|
int position |
the position of the view to scroll to |