java.lang.Object | |
↳ | android.support.v7.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.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Gets the Object mapped from the specified id, or
null
if no such data exists.
| |||||||||||
Returns the total number of items that can be laid out.
| |||||||||||
If scroll is triggered to make a certain item visible, this value will return the
adapter index of that item.
| |||||||||||
Returns if current scroll has a target position.
| |||||||||||
Adds a mapping from the specified id to the specified value, replacing the previous
mapping from the specified key if there was one.
| |||||||||||
Removes the mapping from the specified id, if there was any.
| |||||||||||
Returns a string containing a concise, human-readable description of this
object.
| |||||||||||
Returns whether RecyclerView will run predictive animations in this layout pass
or not.
| |||||||||||
Returns whether RecyclerView will run simple animations in this layout pass
or not.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Gets the Object mapped from the specified id, or null
if no such data exists.
resourceId | Id of the resource you want to remove. It is suggested to use R.id.* to preserve cross functionality and avoid conflicts. |
---|
Returns the total number of items that can be laid out. Note that this number is not necessarily equal to the number of items in the adapter, so you should always use this number for your position calculations and never access the adapter directly.
RecyclerView listens for Adapter's notify events and calculates the effects of adapter data changes on existing Views. These calculations are used to decide which animations should be run.
To support predictive animations, RecyclerView may rewrite or reorder Adapter changes to present the correct state to LayoutManager in pre-layout pass.
For example, a newly added item is not included in pre-layout item count because
pre-layout reflects the contents of the adapter before the item is added. Behind the
scenes, RecyclerView offsets getViewForPosition(int)
calls such that
LayoutManager does not know about the new item's existence in pre-layout. The item will
be available in second layout pass and will be included in the item count. Similar
adjustments are made for moved and removed items as well.
You can get the adapter's item count via getItemCount()
method.
If scroll is triggered to make a certain item visible, this value will return the adapter index of that item.
NO_POSITION
if there is no target
position.
Returns if current scroll has a target position.
Adds a mapping from the specified id to the specified value, replacing the previous mapping from the specified key if there was one.
resourceId | Id of the resource you want to add. It is suggested to use R.id.* to preserve cross functionality and avoid conflicts. |
---|---|
data | The data you want to associate with the resourceId. |
Removes the mapping from the specified id, if there was any.
resourceId | Id of the resource you want to remove. It is suggested to use R.id.* to preserve cross functionality and avoid conflicts. |
---|
Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString
method
if you intend implementing your own toString
method.
Returns whether RecyclerView will run predictive animations in this layout pass or not.
Returns whether RecyclerView will run simple animations in this layout pass or not.