RecyclerView.State

public static class RecyclerView.State
extends Object

java.lang.Object
   ↳ androidx.recyclerview.widget.RecyclerView.State


Contains useful information about the current RecyclerView state like target scroll position or view focus. State object can also keep arbitrary data, identified by resource ids.

Often times, RecyclerView components will need to pass information between each other. To provide a well defined data bus between components, RecyclerView passes the same State object to component callbacks and these components can use it to exchange data.

If you implement custom components, you can use State's put/get/remove methods to pass data between your components without needing to manage their lifecycles.

Summary

Public constructors

State()

Public methods

boolean didStructureChange()
<T> T get(int resourceId)

Gets the Object mapped from the specified id, or null if no such data exists.

int getItemCount()

Returns the total number of items that can be laid out.

int getRemainingScrollHorizontal()

Returns remaining horizontal scroll distance of an ongoing scroll animation(fling/ smoothScrollTo/SmoothScroller) in pixels.

int getRemainingScrollVertical()

Returns remaining vertical scroll distance of an ongoing scroll animation(fling/ smoothScrollTo/SmoothScroller) in pixels.

int getTargetScrollPosition()

If scroll is triggered to make a certain item visible, this value will return the adapter index of that item.

boolean hasTargetScrollPosition()

Returns if current scroll has a target position.

boolean isMeasuring()

Returns true if the RecyclerView is currently measuring the layout.

boolean isPreLayout()

Returns true if the RecyclerView is in the pre-layout step where it is having its RecyclerView.LayoutManager layout items where they will be at the beginning of a set of predictive item animations.

void put(int resourceId, Object data)

Adds a mapping from the specified id to the specified value, replacing the previous mapping from the specified key if there was one.

void remove(int resourceId)

Removes the mapping from the specified id, if there was any.

String toString()
boolean willRunPredictiveAnimations()

Returns whether RecyclerView will run predictive animations in this layout pass or not.

boolean willRunSimpleAnimations()

Returns whether RecyclerV