belongs to Maven artifact com.android.support:recyclerview-v7:28.0.0-alpha1
RecyclerView
public
class
RecyclerView
extends ViewGroup
implements
ScrollingView,
NestedScrollingChild2
java.lang.Object | |||
↳ | android.view.View | ||
↳ | android.view.ViewGroup | ||
↳ | android.support.v7.widget.RecyclerView |
![]() |
![]() |
A flexible view for providing a limited window into a large data set.
Glossary of terms:
- Adapter: A subclass of
RecyclerView.Adapter
responsible for providing views that represent items in a data set. - Position: The position of a data item within an Adapter.
- Index: The index of an attached child view as used in a call to
getChildAt(int)
. Contrast with Position. - Binding: The process of preparing a child view to display data corresponding to a position within the adapter.
- Recycle (view): A view previously used to display data for a specific adapter position may be placed in a cache for later reuse to display the same type of data again later. This can drastically improve performance by skipping initial layout inflation or construction.
- Scrap (view): A child view that has entered into a temporarily detached state during layout. Scrap views may be reused without becoming fully detached from the parent RecyclerView, either unmodified if no rebinding is required or modified by the adapter if the view was considered dirty.
- Dirty (view): A child view that must be rebound by the adapter before being displayed.
Positions in RecyclerView:
RecyclerView introduces an additional level of abstraction between the RecyclerView.Adapter
and
RecyclerView.LayoutManager
to be able to detect data set changes in batches during a layout
calculation. This saves LayoutManager from tracking adapter changes to calculate animations.
It also helps with performance because all view bindings happen at the same time and unnecessary
bindings are avoided.
For this reason, there are two types of position
related methods in RecyclerView:
- layout position: Position of an item in the latest layout calculation. This is the position from the LayoutManager's perspective.
- adapter position: Position of an item in the adapter. This is the position from the Adapter's perspective.
These two positions are the same except the time between dispatching adapter.notify*
events and calculating the updated layout.
Methods that return or receive *LayoutPosition*
use position as of the latest
layout calculation (e.g. getLayoutPosition()
,
findViewHolderForLayoutPosition(int)
). These positions include all changes until the
last layout calculation. You can rely on these positions to be consistent with what user is
currently seeing on the screen. For example, if you have a list of items on the screen and user
asks for the 5th element, you should use these methods as they'll match what user
is seeing.
The other set of position related methods are in the form of
*AdapterPosition*
. (e.g. getAdapterPosition()
,
findViewHolderForAdapterPosition(int)
) You should use these methods when you need to
work with up-to-date adapter positions even if they may not have been reflected to layout yet.
For example, if you want to access the item in the adapter on a ViewHolder click, you should use
getAdapterPosition()
. Beware that these methods may not be able to calculate
adapter positions if notifyDataSetChanged()
has been called and new layout has
not yet been calculated. For this reasons, you should carefully handle NO_POSITION
or
null
results from these methods.
When writing a RecyclerView.LayoutManager
you almost always want to use layout positions whereas when
writing an RecyclerView.Adapter
, you probably want to use adapter positions.
Summary
Nested classes | |
---|---|
class |
RecyclerView.Adapter<VH extends RecyclerView.ViewHolder>
Base class for an Adapter Adapters provide a binding from an app-specific data set to views that are displayed
within a |
class |
RecyclerView.AdapterDataObserver
Observer base class for watching changes to an |
interface |
RecyclerView.ChildDrawingOrderCallback
A callback interface that can be used to alter the drawing order of RecyclerView children. |
class |
RecyclerView.EdgeEffectFactory
EdgeEffectFactory lets you customize the over-scroll edge effect for RecyclerViews. |
class |
RecyclerView.ItemAnimator
This class defines the animations that take place on items as changes are made to the adapter. |
class |
RecyclerView.ItemDecoration
An ItemDecoration allows the application to add a special drawing and layout offset to specific item views from the adapter's data set. |
class |
RecyclerView.LayoutManager
A |
class |
RecyclerView.LayoutParams
|
interface |
RecyclerView.OnChildAttachStateChangeListener
A Listener interface that can be attached to a RecylcerView to get notified whenever a ViewHolder is attached to or detached from RecyclerView. |
class |
RecyclerView.OnFlingListener
This class defines the behavior of fling if the developer wishes to handle it. |
interface |
RecyclerView.OnItemTouchListener
An OnItemTouchListener allows the application to intercept touch events in progress at the view hierarchy level of the RecyclerView before those touch events are considered for RecyclerView's own scrolling behavior. |
class |
RecyclerView.OnScrollListener
An OnScrollListener can be added to a RecyclerView to receive messages when a scrolling event has occurred on that RecyclerView. |
class |
RecyclerView.RecycledViewPool
RecycledViewPool lets you share Views between multiple RecyclerViews. |
class |
RecyclerView.Recycler
A Recycler is responsible for managing scrapped or detached item views for reuse. |
interface |
RecyclerView.RecyclerListener
A RecyclerListener can be set on a RecyclerView to receive messages whenever a view is recycled. |
class |
RecyclerView.SimpleOnItemTouchListener
An implementation of |
class |
RecyclerView.SmoothScroller
Base class for smooth scrolling. |
class |
RecyclerView.State
Contains useful information about the current RecyclerView state like target scroll position or view focus. |
class |
RecyclerView.ViewCacheExtension
ViewCacheExtension is a helper class to provide an additional layer of view caching that can be controlled by the developer. |
class |
RecyclerView.ViewHolder
A ViewHolder describes an item view and metadata about its place within the RecyclerView. |
XML attributes | |
---|---|
RecyclerView_layoutManager |
Constants | |
---|---|
int |
HORIZONTAL
|
int |
INVALID_TYPE
|
long |
NO_ID
|
int |
NO_POSITION
|
int |
SCROLL_STATE_DRAGGING
The RecyclerView is currently being dragged by outside input such as user touch input. |
int |
SCROLL_STATE_IDLE
The RecyclerView is not currently scrolling. |
int |
SCROLL_STATE_SETTLING
The RecyclerView is currently animating to a final position while not under outside control. |
int |
TOUCH_SLOP_DEFAULT
Constant for use with |
int |
TOUCH_SLOP_PAGING
Constant for use with |
int |
VERTICAL
|
Inherited constants |
---|
![]()
android.view.ViewGroup
|
![]()
android.view.View
|