Class Overview
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 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()
|
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
|
isPreLayout()
|
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.
|
[Expand]
Inherited Methods |
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this Object .
|
boolean
|
equals(Object o)
Compares this instance with the specified object and indicates if they
are equal.
|
void
|
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
final
Class<?>
|
getClass()
Returns the unique instance of Class that represents this
object's class.
|
int
|
hashCode()
Returns an integer hash code for this object.
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
final
void
|
wait(long millis, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait(long millis)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
|
Public Constructors
public
RecyclerView.State
()
Public Methods
public
boolean
didStructureChange
()
Returns
- true if the structure of the data set has changed since the last call to
onLayoutChildren, false otherwise
public
T
get
(int resourceId)
Gets the Object mapped from the specified id, or null
if no such data exists.
Parameters
resourceId
| Id of the resource you want to remove. It is suggested to use R.id.*
to
preserve cross functionality and avoid conflicts.
|
public
int
getItemCount
()
Returns
- Total number of items to 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 call adapter directly.
public
int
getTargetScrollPosition
()
If scroll is triggered to make a certain item visible, this value will return the
adapter index of that item.
Returns
- Adapter index of the target item or
NO_POSITION
if there is no target
position.
public
boolean
hasTargetScrollPosition
()
Returns if current scroll has a target position.
Returns
- true if scroll is being triggered to make a certain position visible
public
boolean
isPreLayout
()
public
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.
Parameters
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.
|
public
void
remove
(int resourceId)
Removes the mapping from the specified id, if there was any.
Parameters
resourceId
| Id of the resource you want to remove. It is suggested to use R.id.* to
preserve cross functionality and avoid conflicts.
|