RecyclerView
public class RecyclerView extends ViewGroup implements ScrollingView, NestedScrollingChild2, NestedScrollingChild3
| java.lang.Object | |||
| ↳ | android.view.View | ||
| ↳ | android.view.ViewGroup | ||
| ↳ | androidx.recyclerview.widget.RecyclerView |
BaseGridView |
An abstract base class for vertically and horizontally scrolling lists. |
WearableRecyclerView |
Wearable specific implementation of the |
HorizontalGridView |
A |
VerticalGridView |
A |
A flexible view for providing a limited window into a large data set.
Glossary of terms:
- Adapter: A subclass of
Adapterresponsible 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. 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 Adapter and 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). 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. getAbsoluteAdapterPosition, getBindingAdapterPosition, findViewHolderForAdapterPosition) 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 getBindingAdapterPosition. 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 LayoutManager you almost always want to use layout positions whereas when writing an Adapter, you probably want to use adapter positions.
Presenting Dynamic Data
To display updatable data in a RecyclerView, your adapter needs to signal inserts, moves, and deletions to RecyclerView. You can build this yourself by manually callingadapter.notify* methods when content changes, or you can use one of the easier solutions RecyclerView provides: List diffing with DiffUtil If your RecyclerView is displaying a list that is re-fetched from scratch for each update (e.g. from the network, or from a database), DiffUtil can calculate the difference between versions of the list. DiffUtil takes both lists as input and computes the difference, which can be passed to RecyclerView to trigger minimal animations and updates to keep your UI performant, and animations meaningful. This approach requires that each list is represented in memory with immutable content, and relies on receiving updates as new instances of lists. This approach is also ideal if your UI layer doesn't implement sorting, it just presents the data in the order it's given.
The best part of this approach is that it extends to any arbitrary changes - item updates, moves, addition and removal can all be computed and handled the same way. Though you do have to keep two copies of the list in memory while diffing, and must avoid mutating them, it's possible to share unmodified elements between list versions.
There are three primary ways to do this for RecyclerView. We recommend you start with ListAdapter, the higher-level API that builds in List diffing on a background thread, with minimal code. AsyncListDiffer also provides this behavior, but without defining an Adapter to subclass. If you want more control, DiffUtil is the lower-level API you can use to compute the diffs yourself. Each approach allows you to specify how diffs should be computed based on item data.
SortedList to manage your list. You define how to order items, and it will automatically trigger update signals that RecyclerView can use. SortedList works if you only need to handle insert and remove events, and has the benefit that you only ever need to have a single copy of the list in memory. It can also compute differences with replaceAll, but this method is more limited than the list diffing behavior above. Paging Library The Paging library extends the diff-based approach to additionally support paged loading. It provides the androidx.paging.PagedList class that operates as a self-loading list, provided a source of data like a database, or paginated network API. It provides convenient list diffing support out of the box, similar to ListAdapter and AsyncListDiffer. For more information about the Paging library, see the library documentation. layoutManager
Summary
Nested types |
|---|
public abstract class RecyclerView.Adapter<VH extends RecyclerView.ViewHolder>Base class for an Adapter |
public enum RecyclerView.Adapter.StateRestorationPolicyDefines how this Adapter wants to restore its state after a view reconstruction (e.g. configuration change). |
public abstract class RecyclerView.AdapterDataObserverObserver base class for watching changes to an |
public interface RecyclerView.ChildDrawingOrderCallbackA callback interface that can be used to alter the drawing order of RecyclerView children. |
public class RecyclerView.EdgeEffectFactoryEdgeEffectFactory lets you customize the over-scroll edge effect for RecyclerViews. |
@Retention(value = RetentionPolicy.SOURCE) |
public abstract class RecyclerView.ItemAnimatorThis class defines the animations that take place on items as changes are made to the adapter. |
@IntDef(flag = true, value = )The set of flags that might be passed to |
public interface RecyclerView.ItemAnimator.ItemAnimatorFinishedListenerThis interface is used to inform listeners when all pending or running animations in an ItemAnimator are finished. |
public class RecyclerView.ItemAnimator.ItemHolderInfoA simple data structure that holds information about an item's bounds. |
public abstract class RecyclerView.ItemDecorationAn ItemDecoration allows the application to add a special drawing and layout offset to specific item views from the adapter's data set. |
public abstract class RecyclerView.LayoutManagerA |
public interface RecyclerView.LayoutManager.LayoutPrefetchRegistryInterface for LayoutManagers to request items to be prefetched, based on position, with specified distance from viewport, which indicates priority. |
public class RecyclerView.LayoutManager.PropertiesSome general properties that a LayoutManager may want to use. |
public class RecyclerView.LayoutParams extends ViewGroup.MarginLayoutParams
|
public interface RecyclerView.OnChildAttachStateChangeListenerA Listener interface that can be attached to a RecylcerView to get notified whenever a ViewHolder is attached to or detached from RecyclerView. |
public abstract class RecyclerView.OnFlingListenerThis class defines the behavior of fling if the developer wishes to handle it. |
public interface RecyclerView.OnItemTouchListenerAn 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. |
public abstract class RecyclerView.OnScrollListenerAn OnScrollListener can be added to a RecyclerView to receive messages when a scrolling event has occurred on that RecyclerView. |
public class RecyclerView.RecycledViewPoolRecycledViewPool lets you share Views between multiple RecyclerViews. |
public final inner class RecyclerView.RecyclerA Recycler is responsible for managing scrapped or detached item views for reuse. |
public interface RecyclerView.RecyclerListenerA RecyclerListener can be set on a RecyclerView to receive messages whenever a view is recycled. |
public class RecyclerView.SimpleOnItemTouchListener implements RecyclerView.OnItemTouchListenerAn implementation of |
public abstract class RecyclerView.SmoothScrollerBase class for smooth scrolling. |
public class RecyclerView.SmoothScroller.ActionHolds information about a smooth scroll request by a |
public interface RecyclerView.SmoothScroller.ScrollVectorProviderAn interface which is optionally implemented by custom |
public class RecyclerView.StateContains useful information about the current RecyclerView state like target scroll position or view focus. |
public abstract class RecyclerView.ViewCacheExtensionViewCacheExtension is a helper class to provide an additional layer of view caching that can be controlled by the developer. |
public abstract class RecyclerView.ViewHolderA ViewHolder describes an item view and metadata about its place within the RecyclerView. |
Constants |
|
|---|---|
static final int |
HORIZONTAL = 0 |
static final int |
INVALID_TYPE = -1 |
static final long |
NO_ID = -1 |
static final int |
NO_POSITION = -1 |
static final int |
The RecyclerView is currently being dragged by outside input such as user touch input. |
static final int |
The RecyclerView is not currently scrolling. |
static final int |
The RecyclerView is currently animating to a final position while not under outside control. |
static final int |
Constant for use with |
static final int |
Constant for use with |
static final int |
UNDEFINED_DURATION = -2147483648Constant that represents that a duration has not been defined. |
static final int |
VERTICAL = 1 |
Public constructors |
|---|
RecyclerView(@NonNull Context context) |
RecyclerView(@NonNull Context context, @Nullable AttributeSet attrs) |
RecyclerView( |
Public methods |
|
|---|---|
void |
addFocusables(ArrayList<View> views, int direction, int focusableMode) |
void |
Add an |
void |
addItemDecoration(@NonNull RecyclerView.ItemDecoration decor, int index)Add an |
void |
addOnChildAttachStateChangeListener(Register a listener that will be notified whenever a child view is attached to or detached from RecyclerView. |
void |
Add an |
void |
Add a listener that will be notified of any changes in scroll state or position. |
void |
Register a listener that will be notified whenever a child view is recycled. |
void |
Removes all listeners that were added via |
void |
Remove all secondary listener that were notified of any changes in scroll state or position. |
int |
Compute the horizontal extent of the horizontal scrollbar's thumb within the horizontal range. |
int |
Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range. |
int |
Compute the horizontal range that the horizontal scrollbar represents. |
int |
Compute the vertical extent of the vertical scrollbar's thumb within the vertical range. |
int |
Compute the vertical offset of the vertical scrollbar's thumb within the vertical range. |
int |
Compute the vertical range that the vertical scrollbar represents. |
boolean |
dispatchKeyEvent(@Nullable KeyEvent event) |
boolean |
dispatchNestedFling(float velocityX, float velocityY, boolean consumed) |
boolean |
dispatchNestedPreFling(float velocityX, float velocityY) |
boolean |
dispatchNestedPreScroll( |
boolean |
dispatchNestedPreScroll(Dispatch one step of a nested scroll in progress before this view consumes any portion of it. |
boolean |
dispatchNestedScroll( |
boolean |
dispatchNestedScroll(Dispatch one step of a nested scroll in progress. |
final void |
dispatchNestedScroll(Dispatch one step of a nested scroll in progress. |
boolean |
|
void |
|
boolean |
|
@Nullable View |
findChildViewUnder(float x, float y)Find the topmost view under the given point. |
@Nullable View |
findContainingItemView(@NonNull View view)Traverses the ancestors of the given view and returns the item view that contains it and also a direct child of the RecyclerView. |
@Nullable RecyclerView.ViewHolder |
findContainingViewHolder(@NonNull View view)Returns the ViewHolder that contains the given view. |
@Nullable RecyclerView.ViewHolder |
findViewHolderForAdapterPosition(int position)Return the ViewHolder for the item in the given position of the data set. |
RecyclerView.ViewHolder |
findViewHolderForItemId(long id)Return the ViewHolder for the item with the given id. |
@Nullable RecyclerView.ViewHolder |
findViewHolderForLayoutPosition(int position)Return the ViewHolder for the item in the given position of the data set as of the latest layout pass. |
@Nullable RecyclerView.ViewHolder |
This method is deprecated. use |
boolean |
fling(int velocityX, int velocityY)Begin a standard fling with an initial velocity along each axis in pixels per second. |
View |
focusSearch(View focused, int direction)Since RecyclerView is a collection ViewGroup that includes virtual children (items that are in the Adapter but not visible in the UI), it employs a more involved focus search strategy that differs from other ViewGroups. |
ViewGroup.LayoutParams |
generateLayoutParams(AttributeSet attrs) |
CharSequence |
|
@Nullable RecyclerView.Adapter |
Retrieves the previously set adapter or null if no adapter is set. |
int |
Return the offset of the RecyclerView's text baseline from the its top boundary. |
int |
getChildAdapterPosition(@NonNull View child)Return the adapter position that the given child view corresponds to. |
long |
getChildItemId(@NonNull View child)Return the stable item id that the given child view corresponds to. |
int |
getChildLayoutPosition(@NonNull View child)Return the adapter position of the given child view as of the latest completed layout pass. |
int |
This method is deprecated. |
RecyclerView.ViewHolder |
getChildViewHolder(@NonNull View child)Retrieve the |
boolean |
Returns whether this RecyclerView will clip its children to its padding, and resize (but not clip) any EdgeEffect to the padded region, if padding is present. |
@Nullable RecyclerViewAccessibilityDelegate |
Returns the accessibility delegate compatibility implementation used by the RecyclerView. |
void |
getDecoratedBoundsWithMargins(@NonNull View view, @NonNull Rect outBounds)Returns the bounds of the view including its decoration and margins. |
@NonNull RecyclerView.EdgeEffectFactory |
Retrieves the previously set |
@Nullable RecyclerView.ItemAnimator |
Gets the current ItemAnimator for this RecyclerView. |
@NonNull RecyclerView.ItemDecoration |
getItemDecorationAt(int index)Returns an |
int |
Returns the number of |
@Nullable RecyclerView.LayoutManager |
Return the |
int |
Returns the maximum fling velocity used by this RecyclerView. |
int |
Returns the minimum velocity to start a fling. |
@Nullable RecyclerView.OnFlingListener |
Get the current |
boolean |
Returns true if the RecyclerView should attempt to preserve currently focused Adapter Item's focus even if the View representing the Item is replaced during a layout calculation. |
@NonNull RecyclerView.RecycledViewPool |
Retrieve this RecyclerView's |
int |
Return the current scrolling state of the RecyclerView. |
boolean |
|
boolean |
|
boolean |
hasNestedScrollingParent(int type)Returns true if this view has a nested scrolling parent for the given input type. |
boolean |
Returns whether there are pending adapter updates which are not yet applied to the layout. |
void |
Invalidates all ItemDecorations. |
boolean |
Returns true if RecyclerView is currently running some animations. |
boolean |
Returns true if RecyclerView is attached to window. |
boolean |
Returns whether RecyclerView is currently computing a layout. |
boolean |
This method is deprecated. Use |
final boolean |
Returns whether layout and scroll calls on this container are currently being suppressed, due to an earlier call to |
boolean |
|
void |
nestedScrollBy(int x, int y)Same as |
void |
offsetChildrenHorizontal(@Px int dx)Offset the bounds of all child views by |
void |
offsetChildrenVertical(@Px int dy)Offset the bounds of all child views by |
void |
onChildAttachedToWindow(@NonNull View child)Called when an item view is attached to this RecyclerView. |
void |
onChildDetachedFromWindow(@NonNull View child)Called when an item view is detached from this RecyclerView. |
void |
|
boolean |
onGenericMotionEvent(MotionEvent event) |
boolean |
|
void |
onScrollStateChanged(int state)Called when the scroll state of this RecyclerView changes. |
void |
onScrolled(@Px int dx, @Px int dy)Called when the scroll position of this RecyclerView changes. |
boolean |
|
void |
Remove an |
void |
removeItemDecorationAt(int index)Removes the |
void |
removeOnChildAttachStateChangeListener(Removes the provided listener from child attached state listeners list. |
void |
Remove an |
void |
Remove a listener that was notified of any changes in scroll state or position. |
void |
Removes the provided listener from RecyclerListener list. |
void |
requestChildFocus(View child, View focused) |
boolean |
requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) |
void |
requestDisallowInterceptTouchEvent(boolean disallowIntercept) |
void |
|
void |
scrollBy(int x, int y) |
void |
scrollTo(int x, int y) |
void |
scrollToPosition(int position)Convenience method to scroll to a certain position. |
void |
|
void |
setAccessibilityDelegateCompat(Sets the accessibility delegate compatibility implementation used by RecyclerView. |
void |
setAdapter(@Nullable RecyclerView.Adapter adapter)Set a new adapter to provide child views on demand. |
void |
setChildDrawingOrderCallback(Sets the |
void |
setClipToPadding(boolean clipToPadding) |
static void |
setDebugAssertionsEnabled(boolean debugAssertionsEnabled)Enable internal assertions about RecyclerView's state and throw exceptions if the assertions are violated. |
void |
setEdgeEffectFactory(Set a |
void |
setHasFixedSize(boolean hasFixedSize)RecyclerView can perform several optimizations if it can know in advance that RecyclerView's size is not affected by the adapter contents. |
void |
setItemAnimator(@Nullable RecyclerView.ItemAnimator animator)Sets the |
void |
setItemViewCacheSize(int size)Set the number of offscreen views to retain before adding them to the potentially shared |
void |
This method is deprecated. Use |
void |
Set the |
void |
This method is deprecated. Use |
void |
setNestedScrollingEnabled(boolean enabled) |
void |
setOnFlingListener(Set a |
void |
This method is deprecated. |
void |
setPreserveFocusAfterLayout(boolean preserveFocusAfterLayout)Set whether the RecyclerView should try to keep the same Item focused after a layout calculation or not. |
void |
Recycled view pools allow multiple RecyclerViews to share a common pool of scrap views. |
void |
This method is deprecated. |
void |
setScrollingTouchSlop(int slopConstant)Configure the scrolling touch slop for a specific use case. |
static void |
setVerboseLoggingEnabled(boolean verboseLoggingEnabled)Enable verbose logging within RecyclerView itself. |
void |
setViewCacheExtension(Sets a new |
void |
smoothScrollBy(@Px int dx, @Px int dy)Animate a scroll by the given amount of pixels along either axis. |
void |
smoothScrollBy(@Px int dx, @Px int dy, @Nullable Interpolator interpolator)Animate a scroll by the given amount of pixels along either axis. |
void |
smoothScrollBy(Smooth scrolls the RecyclerView by a given distance. |
void |
smoothScrollToPosition(int position)Starts a smooth scroll to an adapter position. |
boolean |
startNestedScroll(int axes) |
boolean |
startNestedScroll(int axes, int type)Begin a nestable scroll operation along the given axes, for the given input type. |
void |
|
void |
stopNestedScroll(int type)Stop a nested scroll in progress for the given input type. |
void |
Stop any current scroll in progress, such as one started by |
final void |
suppressLayout(boolean suppress)Tells this RecyclerView to suppress all layout and scroll calls until layout suppression is disabled with a later call to suppressLayout(false). |
void |
swapAdapter(Swaps the current adapter with the provided one. |
Protected methods |
|
|---|---|
boolean |
|
void |
dispatchRestoreInstanceState(SparseArray<Parcelable> container)Override to prevent thawing of any views created by the adapter. |
void |
dispatchSaveInstanceState(SparseArray<Parcelable> container)Override to prevent freezing of any views created by the adapter. |
ViewGroup.LayoutParams |
|
ViewGroup.LayoutParams |
|
int |
getChildDrawingOrder(int childCount, int i) |
void |
|
void |
|
void |
onLayout(boolean changed, int l, int t, int r, int b) |
void |
onMeasure(int widthSpec, int heightSpec) |
boolean |
onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) |
void |
onRestoreInstanceState(Parcelable state) |
Parcelable |
|
void |
onSizeChanged(int w, int h, int oldw, int oldh) |
void |
removeDetachedView(View child, boolean animate) |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Inherited methods |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constants
SCROLL_STATE_DRAGGING
public static final int SCROLL_STATE_DRAGGING = 1
The RecyclerView is currently being dragged by outside input such as user touch input.
| See also | |
|---|---|
getScrollState |
SCROLL_STATE_IDLE
public static final int SCROLL_STATE_IDLE = 0
The RecyclerView is not currently scrolling.
| See also | |
|---|---|
getScrollState |
SCROLL_STATE_SETTLING
public static final int SCROLL_STATE_SETTLING = 2
The RecyclerView is currently animating to a final position while not under outside control.
| See also | |
|---|---|
getScrollState |
TOUCH_SLOP_DEFAULT
public static final int TOUCH_SLOP_DEFAULT = 0
Constant for use with setScrollingTouchSlop. Indicates that the RecyclerView should use the standard touch slop for smooth, continuous scrolling.
TOUCH_SLOP_PAGING
public static final int TOUCH_SLOP_PAGING = 1
Constant for use with setScrollingTouchSlop. Indicates that the RecyclerView should use the standard touch slop for scrolling widgets that snap to a page or other coarse-grained barrier.
UNDEFINED_DURATION
public static final int UNDEFINED_DURATION = -2147483648
Constant that represents that a duration has not been defined.
Public constructors
RecyclerView
public RecyclerView(@NonNull Context context, @Nullable AttributeSet attrs)
RecyclerView
public RecyclerView(
@NonNull Context context,
@Nullable AttributeSet attrs,
int defStyleAttr
)
Public methods
addItemDecoration
public void addItemDecoration(@NonNull RecyclerView.ItemDecoration decor)
Add an ItemDecoration to this RecyclerView. Item decorations can affect both measurement and drawing of individual item views.
Item decorations are ordered. Decorations placed earlier in the list will be run/queried/drawn first for their effects on item views. Padding added to views will be nested; a padding added by an earlier decoration will mean further item decorations in the list will be asked to draw/pad within the previous decoration's given area.
| Parameters | |
|---|---|
@NonNull RecyclerView.ItemDecoration decor |
Decoration to add |
addItemDecoration
public void addItemDecoration(@NonNull RecyclerView.ItemDecoration decor, int index)
Add an ItemDecoration to this RecyclerView. Item decorations can affect both measurement and drawing of individual item views.
Item decorations are ordered. Decorations placed earlier in the list will be run/queried/drawn first for their effects on item views. Padding added to views will be nested; a padding added by an earlier decoration will mean further item decorations in the list will be asked to draw/pad within the previous decoration's given area.
| Parameters | |
|---|---|
@NonNull RecyclerView.ItemDecoration decor |
Decoration to add |
int index |
Position in the decoration chain to insert this decoration at. If this value is negative the decoration will be added at the end. |
addOnChildAttachStateChangeListener
public void addOnChildAttachStateChangeListener(
@NonNull RecyclerView.OnChildAttachStateChangeListener listener
)
Register a listener that will be notified whenever a child view is attached to or detached from RecyclerView.
This listener will be called when a LayoutManager or the RecyclerView decides that a child view is no longer needed. If an application associates expensive or heavyweight data with item views, this may be a good place to release or free those resources.
| Parameters | |
|---|---|
@NonNull RecyclerView.OnChildAttachStateChangeListener listener |
Listener to register |
addOnItemTouchListener
public void addOnItemTouchListener(
@NonNull RecyclerView.OnItemTouchListener listener
)
Add an OnItemTouchListener to intercept touch events before they are dispatched to child views or this view's standard scrolling behavior.
Client code may use listeners to implement item manipulation behavior. Once a listener returns true from onInterceptTouchEvent its onTouchEvent method will be called for each incoming MotionEvent until the end of the gesture.
| Parameters | |
|---|---|
@NonNull RecyclerView.OnItemTouchListener listener |
Listener to add |
addOnScrollListener
public void addOnScrollListener(@NonNull RecyclerView.OnScrollListener listener)
Add a listener that will be notified of any changes in scroll state or position.
Components that add a listener should take care to remove it when finished. Other components that take ownership of a view may call clearOnScrollListeners to remove all attached listeners.
| Parameters | |
|---|---|
@NonNull RecyclerView.OnScrollListener listener |
listener to set |
addRecyclerListener
public void addRecyclerListener(@NonNull RecyclerView.RecyclerListener listener)
Register a listener that will be notified whenever a child view is recycled.
The listeners will be called when a LayoutManager or the RecyclerView decides that a child view is no longer needed. If an application associates data with the item views being recycled, this may be a good place to release or free those resources.
| Parameters | |
|---|---|
@NonNull RecyclerView.RecyclerListener listener |
Listener to register. |
clearOnChildAttachStateChangeListeners
public void clearOnChildAttachStateChangeListeners()
Removes all listeners that were added via addOnChildAttachStateChangeListener.
clearOnScrollListeners
public void clearOnScrollListeners()
Remove all secondary listener that were notified of any changes in scroll state or position.
computeHorizontalScrollExtent
public int computeHorizontalScrollExtent()
Compute the horizontal extent of the horizontal scrollbar's thumb within the horizontal range. This value is used to compute the length of the thumb within the scrollbar's track.
The range is expressed in arbitrary units that must be the same as the units used by computeHorizontalScrollRange and computeHorizontalScrollOffset.
Default implementation returns 0.
If you want to support scroll bars, override computeHorizontalScrollExtent in your LayoutManager.
| Returns | |
|---|---|
int |
The horizontal extent of the scrollbar's thumb |
| See also | |
|---|---|
computeHorizontalScrollExtent |
computeHorizontalScrollOffset
public int computeHorizontalScrollOffset()
Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range. This value is used to compute the position of the thumb within the scrollbar's track.
The range is expressed in arbitrary units that must be the same as the units used by computeHorizontalScrollRange and computeHorizontalScrollExtent.
Default implementation returns 0.
If you want to support scroll bars, override computeHorizontalScrollOffset in your LayoutManager.
| Returns | |
|---|---|
int |
The horizontal offset of the scrollbar's thumb |
| See also | |
|---|---|
computeHorizontalScrollOffset |
(RecyclerView.State) |
computeHorizontalScrollRange
public int computeHorizontalScrollRange()
Compute the horizontal range that the horizontal scrollbar represents.
The range is expressed in arbitrary units that must be the same as the units used by computeHorizontalScrollExtent and computeHorizontalScrollOffset.
Default implementation returns 0.
If you want to support scroll bars, override computeHorizontalScrollRange in your LayoutManager.
| Returns | |
|---|---|
int |
The total horizontal range represented by the horizontal scrollbar |
| See also | |
|---|---|
computeHorizontalScrollRange |
computeVerticalScrollExtent
public int computeVerticalScrollExtent()
Compute the vertical extent of the vertical scrollbar's thumb within the vertical range. This value is used to compute the length of the thumb within the scrollbar's track.
The range is expressed in arbitrary units that must be the same as the units used by computeVerticalScrollRange and computeVerticalScrollOffset.
Default implementation returns 0.
If you want to support scroll bars, override computeVerticalScrollExtent in your LayoutManager.
| Returns | |
|---|---|
int |
The vertical extent of the scrollbar's thumb |
| See also | |
|---|---|
computeVerticalScrollExtent |
computeVerticalScrollOffset
public int computeVerticalScrollOffset()
Compute the vertical offset of the vertical scrollbar's thumb within the vertical range. This value is used to compute the position of the thumb within the scrollbar's track.
The range is expressed in arbitrary units that must be the same as the units used by computeVerticalScrollRange and computeVerticalScrollExtent.
Default implementation returns 0.
If you want to support scroll bars, override computeVerticalScrollOffset in your LayoutManager.
| Returns | |
|---|---|
int |
The vertical offset of the scrollbar's thumb |
| See also | |
|---|---|
computeVerticalScrollOffset |
(RecyclerView.State) |
computeVerticalScrollRange
public int computeVerticalScrollRange()
Compute the vertical range that the vertical scrollbar represents.
The range is expressed in arbitrary units that must be the same as the units used by computeVerticalScrollExtent and computeVerticalScrollOffset.
Default implementation returns 0.
If you want to support scroll bars, override computeVerticalScrollRange in your LayoutManager.
| Returns | |
|---|---|
int |
The total vertical range represented by the vertical scrollbar |
| See also | |
|---|---|
computeVerticalScrollRange |
dispatchNestedFling
public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed)
dispatchNestedPreScroll
public boolean dispatchNestedPreScroll(
int dx,
int dy,
int[] consumed,
int[] offsetInWindow
)
dispatchNestedPreScroll
public boolean dispatchNestedPreScroll(
int dx,
int dy,
int[] consumed,
int[] offsetInWindow,
int type
)
Dispatch one step of a nested scroll in progress before this view consumes any portion of it.
Nested pre-scroll events are to nested scroll events what touch intercept is to touch. dispatchNestedPreScroll offers an opportunity for the parent view in a nested scrolling operation to consume some or all of the scroll operation before the child view consumes it.
| Parameters | |
|---|---|
int dx |
Horizontal scroll distance in pixels |
int dy |
Vertical scroll distance in pixels |
int[] consumed |
Output. If not null, consumed[0] will contain the consumed component of dx and consumed[1] the consumed dy. |
int[] offsetInWindow |
Optional. If not null, on return this will contain the offset in local view coordinates of this view from before this operation to after it completes. View implementations may use this to adjust expected input coordinate tracking. |
int type |
the type of input which cause this scroll event |
| Returns | |
|---|---|
boolean |
true if the parent consumed some or all of the scroll delta |
| See also | |
|---|---|
dispatchNestedScroll |
dispatchNestedScroll
public boolean dispatchNestedScroll(
int dxConsumed,
int dyConsumed,
int dxUnconsumed,
int dyUnconsumed,
int[] offsetInWindow
)
dispatchNestedScroll
public boolean dispatchNestedScroll(
int dxConsumed,
int dyConsumed,
int dxUnconsumed,
int dyUnconsumed,
int[] offsetInWindow,
int type
)
Dispatch one step of a nested scroll in progress.
Implementations of views that support nested scrolling should call this to report info about a scroll in progress to the current nested scrolling parent. If a nested scroll is not currently in progress or nested scrolling is not enabled for this view this method does nothing.
Compatible View implementations should also call dispatchNestedPreScroll before consuming a component of the scroll event themselves.
| Parameters | |
|---|---|
int dxConsumed |
Horizontal distance in pixels consumed by this view during this scroll step |
int dyConsumed |
Vertical distance in pixels consumed by this view during this scroll step |
int dxUnconsumed |
Horizontal scroll distance in pixels not consumed by this view |
int dyUnconsumed |
Horizontal scroll distance in pixels not consumed by this view |
int[] offsetInWindow |
Optional. If not null, on return this will contain the offset in local view coordinates of this view from before this operation to after it completes. View implementations may use this to adjust expected input coordinate tracking. |
int type |
the type of input which cause this scroll event |
| Returns | |
|---|---|
boolean |
true if the event was dispatched, false if it could not be dispatched. |
| See also | |
|---|---|
dispatchNestedPreScroll |
dispatchNestedScroll
public final void dispatchNestedScroll(
int dxConsumed,
int dyConsumed,
int dxUnconsumed,
int dyUnconsumed,
int[] offsetInWindow,
int type,
@NonNull int[] consumed
)
Dispatch one step of a nested scroll in progress.
Implementations of views that support nested scrolling should call this to report info about a scroll in progress to the current nested scrolling parent. If a nested scroll is not currently in progress or nested scrolling is not enabled for this view this method does nothing.
Compatible View implementations should also call dispatchNestedPreScroll before consuming a component of the scroll event themselves.
The original nested scrolling child (where the input events were received to start the scroll) must provide a non-null consumed parameter with values {0, 0}.
| Parameters | |
|---|---|
int dxConsumed |
Horizontal distance in pixels consumed by this view during this scroll step |
int dyConsumed |
Vertical distance in pixels consumed by this view during this scroll step |
int dxUnconsumed |
Horizontal scroll distance in pixels not consumed by this view |
int dyUnconsumed |
Horizontal scroll distance in pixels not consumed by this view |
int[] offsetInWindow |
Optional. If not null, on return this will contain the offset in local view coordinates of this view from before this operation to after it completes. View implementations may use this to adjust expected input coordinate tracking. |
int type |
the type of input which cause this scroll event |
@NonNull int[] consumed |
Output. Upon this method returning, will contain the original values plus any scroll distances consumed by all of this view's nested scrolling parents up the view hierarchy. Index 0 for the x dimension, and index 1 for the y dimension |
| See also | |
|---|---|
onNestedScroll |
dispatchPopulateAccessibilityEvent
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event)
drawChild
public boolean drawChild(@NonNull Canvas canvas, View child, long drawingTime)
findChildViewUnder
public @Nullable View findChildViewUnder(float x, float y)
Find the topmost view under the given point.
| Parameters | |
|---|---|
float x |
Horizontal position in pixels to search |
float y |
Vertical position in pixels to search |
findContainingItemView
public @Nullable View findContainingItemView(@NonNull View view)
Traverses the ancestors of the given view and returns the item view that contains it and also a direct child of the RecyclerView. This returned view can be used to get the ViewHolder by calling getChildViewHolder.
findContainingViewHolder
public @Nullable RecyclerView.ViewHolder findContainingViewHolder(@NonNull View view)
Returns the ViewHolder that contains the given view.
| Returns | |
|---|---|
@Nullable RecyclerView.ViewHolder |
The ViewHolder that contains the given view or null if the provided view is not a descendant of this RecyclerView. |
findViewHolderForAdapterPosition
public @Nullable RecyclerView.ViewHolder findViewHolderForAdapterPosition(int position)
Return the ViewHolder for the item in the given position of the data set. Unlike findViewHolderForLayoutPosition this method takes into account any pending adapter changes that may not be reflected to the layout yet. On the other hand, if notifyDataSetChanged has been called but the new layout has not been calculated yet, this method will return null since the new positions of views are unknown until the layout is calculated.
This method checks only the children of RecyclerView. If the item at the given position is not laid out, it will not create a new one.
When the ItemAnimator is running a change animation, there might be 2 ViewHolders representing the same Item. In this case, the updated ViewHolder will be returned.
| Parameters | |
|---|---|
int position |
The position of the item in the data set of the adapter |
| Returns | |
|---|---|
@Nullable RecyclerView.ViewHolder |
The ViewHolder at |
findViewHolderForItemId
public RecyclerView.ViewHolder findViewHolderForItemId(long id)
Return the ViewHolder for the item with the given id. The RecyclerView must use an Adapter with stableIds to return a non-null value.
This method checks only the children of RecyclerView. If the item with the given id is not laid out, it will not create a new one. When the ItemAnimator is running a change animation, there might be 2 ViewHolders with the same id. In this case, the updated ViewHolder will be returned.
| Parameters | |
|---|---|
long id |
The id for the requested item |
| Returns | |
|---|---|
RecyclerView.ViewHolder |
The ViewHolder with the given |
findViewHolderForLayoutPosition
public @Nullable RecyclerView.ViewHolder findViewHolderForLayoutPosition(int position)
Return the ViewHolder for the item in the given position of the data set as of the latest layout pass.
This method checks only the children of RecyclerView. If the item at the given position is not laid out, it will not create a new one.
Note that when Adapter contents change, ViewHolder positions are not updated until the next layout calculation. If there are pending adapter updates, the return value of this method may not match your adapter contents. You can use #getBindingAdapterPosition to get the current adapter position of a ViewHolder. If the Adapter that is assigned to the RecyclerView is an adapter that combines other adapters (e.g. ConcatAdapter), you can use the getBindingAdapter) to find the position relative to the Adapter that bound the ViewHolder.
When the ItemAnimator is running a change animation, there might be 2 ViewHolders with the same layout position representing the same Item. In this case, the updated ViewHolder will be returned.
| Parameters | |
|---|---|
int position |
The position of the item in the data set of the adapter |
| Returns | |
|---|---|
@Nullable RecyclerView.ViewHolder |
The ViewHolder at |
fling
public boolean fling(int velocityX, int velocityY)
Begin a standard fling with an initial velocity along each axis in pixels per second. If the velocity given is below the system-defined minimum this method will return false and no fling will occur.
| Parameters | |
|---|---|
int velocityX |
Initial horizontal velocity in pixels per second |
int velocityY |
Initial vertical velocity in pixels per second |
| Returns | |
|---|---|
boolean |
true if the fling was started, false if the velocity was too low to fling or LayoutManager does not support scrolling in the axis fling is issued. |
| See also | |
|---|---|
canScrollVertically |
|
canScrollHorizontally |
focusSearch
public View focusSearch(View focused, int direction)
Since RecyclerView is a collection ViewGroup that includes virtual children (items that are in the Adapter but not visible in the UI), it employs a more involved focus search strategy that differs from other ViewGroups.
It first does a focus search within the RecyclerView. If this search finds a View that is in the focus direction with respect to the currently focused View, RecyclerView returns that child as the next focus target. When it cannot find such child, it calls onFocusSearchFailed to layout more Views in the focus search direction. If LayoutManager adds a View that matches the focus search criteria, it will be returned as the focus search result. Otherwise, RecyclerView will call parent to handle the focus search like a regular ViewGroup.
When the direction is FOCUS_FORWARD or FOCUS_BACKWARD, a View that is not in the focus direction is still valid focus target which may not be the desired behavior if the Adapter has more children in the focus direction. To handle this case, RecyclerView converts the focus direction to an absolute direction and makes a preliminary focus search in that direction. If there are no Views to gain focus, it will call onFocusSearchFailed before running a focus search with the original (relative) direction. This allows RecyclerView to provide better candidates to the focus search while still allowing the view system to take focus from the RecyclerView and give it to a more suitable child if such child exists.
| Parameters | |
|---|---|
View focused |
The view that currently has focus |
int direction |
One of |
| Returns | |
|---|---|
View |
A new View that can be the next focus after the focused View |
getAdapter
public @Nullable RecyclerView.Adapter getAdapter()
Retrieves the previously set adapter or null if no adapter is set.
| Returns | |
|---|---|
@Nullable RecyclerView.Adapter |
The previously set adapter |
| See also | |
|---|---|
setAdapter |
getBaseline
public int getBaseline()
Return the offset of the RecyclerView's text baseline from the its top boundary. If the LayoutManager of this RecyclerView does not support baseline alignment, this method returns -1.
| Returns | |
|---|---|
int |
the offset of the baseline within the RecyclerView's bounds or -1 if baseline alignment is not supported |
getChildAdapterPosition
public int getChildAdapterPosition(@NonNull View child)
Return the adapter position that the given child view corresponds to.
| Returns | |
|---|---|
int |
Adapter position corresponding to the given view or |
getChildItemId
public long getChildItemId(@NonNull View child)
Return the stable item id that the given child view corresponds to.
| Returns | |
|---|---|
long |
Item id corresponding to the given view or |
getChildLayoutPosition
public int getChildLayoutPosition(@NonNull View child)
Return the adapter position of the given child view as of the latest completed layout pass.
This position may not be equal to Item's adapter position if there are pending changes in the adapter which have not been reflected to the layout yet.
| Returns | |
|---|---|
int |
Adapter position of the given View as of last layout pass or |
getChildViewHolder
public RecyclerView.ViewHolder getChildViewHolder(@NonNull View child)
Retrieve the ViewHolder for the given child view.
| Returns | |
|---|---|
RecyclerView.ViewHolder |
The child view's ViewHolder |
getClipToPadding
public boolean getClipToPadding()
Returns whether this RecyclerView will clip its children to its padding, and resize (but not clip) any EdgeEffect to the padded region, if padding is present.
By default, children are clipped to the padding of their parent RecyclerView. This clipping behavior is only enabled if padding is non-zero.
name android:clipToPadding
| Returns | |
|---|---|
boolean |
true if this RecyclerView clips children to its padding and resizes (but doesn't clip) any EdgeEffect to the padded region, false otherwise. |
getCompatAccessibilityDelegate
public @Nullable RecyclerViewAccessibilityDelegate getCompatAccessibilityDelegate()
Returns the accessibility delegate compatibility implementation used by the RecyclerView.
| Returns | |
|---|---|
@Nullable RecyclerViewAccessibilityDelegate |
An instance of AccessibilityDelegateCompat used by RecyclerView |
getDecoratedBoundsWithMargins
public void getDecoratedBoundsWithMargins(@NonNull View view, @NonNull Rect outBounds)
Returns the bounds of the view including its decoration and margins.
getEdgeEffectFactory
public @NonNull RecyclerView.EdgeEffectFactory getEdgeEffectFactory()
Retrieves the previously set EdgeEffectFactory or the default factory if nothing was set.
| Returns | |
|---|---|
@NonNull RecyclerView.EdgeEffectFactory |
The previously set |
| See also | |
|---|---|
setEdgeEffectFactory |
getItemAnimator
public @Nullable RecyclerView.ItemAnimator getItemAnimator()
Gets the current ItemAnimator for this RecyclerView. A null return value indicates that there is no animator and that item changes will happen without any animations. By default, RecyclerView instantiates and uses an instance of DefaultItemAnimator.
| Returns | |
|---|---|
@Nullable RecyclerView.ItemAnimator |
ItemAnimator The current ItemAnimator. If null, no animations will occur when changes occur to the items in this RecyclerView. |
getItemDecorationAt
public @NonNull RecyclerView.ItemDecoration getItemDecorationAt(int index)
Returns an ItemDecoration previously added to this RecyclerView.
| Parameters | |
|---|---|
int index |
The index position of the desired ItemDecoration. |
| Returns | |
|---|---|
@NonNull RecyclerView.ItemDecoration |
the ItemDecoration at index position |
| Throws | |
|---|---|
java.lang.IndexOutOfBoundsException |
on invalid index |
getItemDecorationCount
public int getItemDecorationCount()
Returns the number of ItemDecoration currently added to this RecyclerView.
| Returns | |
|---|---|
int |
number of ItemDecorations currently added added to this RecyclerView. |
getLayoutManager
public @Nullable RecyclerView.LayoutManager getLayoutManager()
Return the LayoutManager currently responsible for layout policy for this RecyclerView.
| Returns | |
|---|---|
@Nullable RecyclerView.LayoutManager |
The currently bound LayoutManager |
getMaxFlingVelocity
public int getMaxFlingVelocity()
Returns the maximum fling velocity used by this RecyclerView.
| Returns | |
|---|---|
int |
The maximum fling velocity used by this RecyclerView. |
getMinFlingVelocity
public int getMinFlingVelocity()
Returns the minimum velocity to start a fling.
| Returns | |
|---|---|
int |
The minimum velocity to start a fling |
getOnFlingListener
public @Nullable RecyclerView.OnFlingListener getOnFlingListener()
Get the current OnFlingListener from this RecyclerView.
| Returns | |
|---|---|
@Nullable RecyclerView.OnFlingListener |
The |
getPreserveFocusAfterLayout
public boolean getPreserveFocusAfterLayout()
Returns true if the RecyclerView should attempt to preserve currently focused Adapter Item's focus even if the View representing the Item is replaced during a layout calculation.
By default, this value is true.
| Returns | |
|---|---|
boolean |
True if the RecyclerView will try to preserve focused Item after a layout if it loses focus. |
| See also | |
|---|---|
setPreserveFocusAfterLayout |
getRecycledViewPool
public @NonNull RecyclerView.RecycledViewPool getRecycledViewPool()
Retrieve this RecyclerView's RecycledViewPool. This method will never return null; if no pool is set for this view a new one will be created. See setRecycledViewPool for more information.
| Returns | |
|---|---|
@NonNull RecyclerView.RecycledViewPool |
The pool used to store recycled item views for reuse. |
| See also | |
|---|---|
setRecycledViewPool |
getScrollState
public int getScrollState()
Return the current scrolling state of the RecyclerView.
| Returns | |
|---|---|
int |
|
hasFixedSize
public boolean hasFixedSize()
| Returns | |
|---|---|
boolean |
true if the app has specified that changes in adapter content cannot change the size of the RecyclerView itself. |
hasNestedScrollingParent
public boolean hasNestedScrollingParent(int type)
Returns true if this view has a nested scrolling parent for the given input type.
The presence of a nested scrolling parent indicates that this view has initiated a nested scroll and it was accepted by an ancestor view further up the view hierarchy.
| Parameters | |
|---|---|
int type |
the type of input which cause this scroll event |
| Returns | |
|---|---|
boolean |
whether this view has a nested scrolling parent |
hasPendingAdapterUpdates
public boolean hasPendingAdapterUpdates()
Returns whether there are pending adapter updates which are not yet applied to the layout.
If this method returns true, it means that what user is currently seeing may not reflect them adapter contents (depending on what has changed). You may use this information to defer or cancel some operations.
This method returns true if RecyclerView has not yet calculated the first layout after it is attached to the Window or the Adapter has been replaced.
| Returns | |
|---|---|
boolean |
True if there are some adapter updates which are not yet reflected to layout or false if layout is up to date. |
invalidateItemDecorations
public void invalidateItemDecorations()
Invalidates all ItemDecorations. If RecyclerView has item decorations, calling this method will trigger a requestLayout call.
isAnimating
public boolean isAnimating()
Returns true if RecyclerView is currently running some animations.
If you want to be notified when animations are finished, use isRunning.
| Returns | |
|---|---|
boolean |
True if there are some item animations currently running or waiting to be started. |
isAttachedToWindow
public boolean isAttachedToWindow()
Returns true if RecyclerView is attached to window.
isComputingLayout
public boolean isComputingLayout()
Returns whether RecyclerView is currently computing a layout.
If this method returns true, it means that RecyclerView is in a lockdown state and any attempt to update adapter contents will result in an exception because adapter contents cannot be changed while RecyclerView is trying to compute the layout.
It is very unlikely that your code will be running during this state as it is called by the framework when a layout traversal happens or RecyclerView starts to scroll in response to system events (touch, accessibility etc).
This case may happen if you have some custom logic to change adapter contents in response to a View callback (e.g. focus change callback) which might be triggered during a layout calculation. In these cases, you should just postpone the change using a Handler or a similar mechanism.
| Returns | |
|---|---|
boolean |
|
isLayoutSuppressed
public final boolean isLayoutSuppressed()
Returns whether layout and scroll calls on this container are currently being suppressed, due to an earlier call to suppressLayout.
| Returns | |
|---|---|
boolean |
true if layout and scroll are currently suppressed, false otherwise. |
nestedScrollBy
public void nestedScrollBy(int x, int y)
Same as scrollBy, but also participates in nested scrolling.
| Parameters | |
|---|---|
int x |
The amount of horizontal scroll requested |
int y |
The amount of vertical scroll requested |
| See also | |
|---|---|
NestedScrollingChild |
offsetChildrenHorizontal
public void offsetChildrenHorizontal(@Px int dx)
Offset the bounds of all child views by dx pixels. Useful for implementing simple scrolling in LayoutManagers.
| Parameters | |
|---|---|
@Px int dx |
Horizontal pixel offset to apply to the bounds of all child views |
offsetChildrenVertical
public void offsetChildrenVertical(@Px int dy)
Offset the bounds of all child views by dy pixels. Useful for implementing simple scrolling in LayoutManagers.
| Parameters | |
|---|---|
@Px int dy |
Vertical pixel offset to apply to the bounds of all child views |
onChildAttachedToWindow
public void onChildAttachedToWindow(@NonNull View child)
Called when an item view is attached to this RecyclerView.
Subclasses of RecyclerView may want to perform extra bookkeeping or modifications of child views as they become attached. This will be called before a LayoutManager measures or lays out the view and is a good time to perform these changes.
onChildDetachedFromWindow
public void onChildDetachedFromWindow(@NonNull View child)
Called when an item view is detached from this RecyclerView.
Subclasses of RecyclerView may want to perform extra bookkeeping or modifications of child views as they become detached. This will be called as a LayoutManager fully detaches the child view from the parent and its window.
onScrollStateChanged
public void onScrollStateChanged(int state)
Called when the scroll state of this RecyclerView changes. Subclasses should use this method to respond to state changes instead of an explicit listener.
This method will always be invoked before listeners, but after the LayoutManager responds to the scroll state change.
| Parameters | |
|---|---|
int state |
the new scroll state, one of |
onScrolled
public void onScrolled(@Px int dx, @Px int dy)
Called when the scroll position of this RecyclerView changes. Subclasses should use this method to respond to scrolling within the adapter's data set instead of an explicit listener.
This method will always be invoked before listeners. If a subclass needs to perform any additional upkeep or bookkeeping after scrolling but before listeners run, this is a good place to do so.
This differs from onScrollChanged in that it receives the distance scrolled in either direction within the adapter's data set instead of absolute scroll coordinates. Since RecyclerView cannot compute the absolute scroll position from any arbitrary point in the data set, onScrollChanged will always receive the current getScrollX and getScrollY values which do not correspond to the data set scroll position. However, some subclasses may choose to use these fields as special offsets.
removeItemDecoration
public void removeItemDecoration(@NonNull RecyclerView.ItemDecoration decor)
Remove an ItemDecoration from this RecyclerView.
The given decoration will no longer impact the measurement and drawing of item views.
| Parameters | |
|---|---|
@NonNull RecyclerView.ItemDecoration decor |
Decoration to remove |
| See also | |
|---|---|
addItemDecoration |
removeItemDecorationAt
public void removeItemDecorationAt(int index)
Removes the ItemDecoration associated with the supplied index position.
| Parameters | |
|---|---|
int index |
The index position of the ItemDecoration to be removed. |
removeOnChildAttachStateChangeListener
public void removeOnChildAttachStateChangeListener(
@NonNull RecyclerView.OnChildAttachStateChangeListener listener
)
Removes the provided listener from child attached state listeners list.
| Parameters | |
|---|---|
@NonNull RecyclerView.OnChildAttachStateChangeListener listener |
Listener to unregister |
removeOnItemTouchListener
public void removeOnItemTouchListener(
@NonNull RecyclerView.OnItemTouchListener listener
)
Remove an OnItemTouchListener. It will no longer be able to intercept touch events.
| Parameters | |
|---|---|
@NonNull RecyclerView.OnItemTouchListener listener |
Listener to remove |
removeOnScrollListener
public void removeOnScrollListener(@NonNull RecyclerView.OnScrollListener listener)
Remove a listener that was notified of any changes in scroll state or position.
| Parameters | |
|---|---|
@NonNull RecyclerView.OnScrollListener listener |
listener to set or null to clear |
removeRecyclerListener
public void removeRecyclerListener(@NonNull RecyclerView.RecyclerListener listener)
Removes the provided listener from RecyclerListener list.
| Parameters | |
|---|---|
@NonNull RecyclerView.RecyclerListener listener |
Listener to unregister. |
requestChildRectangleOnScreen
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate)
requestDisallowInterceptTouchEvent
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept)
scrollToPosition
public void scrollToPosition(int position)
Convenience method to scroll to a certain position. RecyclerView does not implement scrolling logic, rather forwards the call to scrollToPosition
| Parameters | |
|---|---|
int position |
Scroll to this adapter position |
| See also | |
|---|---|
scrollToPosition |
sendAccessibilityEventUnchecked
public void sendAccessibilityEventUnchecked(AccessibilityEvent event)
setAccessibilityDelegateCompat
public void setAccessibilityDelegateCompat(
@Nullable RecyclerViewAccessibilityDelegate accessibilityDelegate
)
Sets the accessibility delegate compatibility implementation used by RecyclerView.
| Parameters | |
|---|---|
@Nullable RecyclerViewAccessibilityDelegate accessibilityDelegate |
The accessibility delegate to be used by RecyclerView. |
setAdapter
public void setAdapter(@Nullable RecyclerView.Adapter adapter)
Set a new adapter to provide child views on demand.
When adapter is changed, all existing views are recycled back to the pool. If the pool has only one adapter, it will be cleared.
| Parameters | |
|---|---|
@Nullable RecyclerView.Adapter adapter |
The new adapter to set, or null to set no adapter. |
| See also | |
|---|---|
swapAdapter |
setChildDrawingOrderCallback
public void setChildDrawingOrderCallback(
@Nullable RecyclerView.ChildDrawingOrderCallback childDrawingOrderCallback
)
Sets the ChildDrawingOrderCallback to be used for drawing children.
See getChildDrawingOrder for details. Calling this method will always call setChildrenDrawingOrderEnabled. The parameter will be true if childDrawingOrderCallback is not null, false otherwise.
Note that child drawing order may be overridden by View's elevation.
| Parameters | |
|---|---|
@Nullable RecyclerView.ChildDrawingOrderCallback childDrawingOrderCallback |
The ChildDrawingOrderCallback to be used by the drawing system. |
setDebugAssertionsEnabled
public static void setDebugAssertionsEnabled(boolean debugAssertionsEnabled)
Enable internal assertions about RecyclerView's state and throw exceptions if the assertions are violated.
This is primarily intended to diagnose problems with RecyclerView, and should not be enabled in production unless you have a specific reason to do so.
Enabling this may negatively affect performance and/or stability.
| Parameters | |
|---|---|
boolean debugAssertionsEnabled |
true to enable assertions; false to disable them |
setEdgeEffectFactory
public void setEdgeEffectFactory(
@NonNull RecyclerView.EdgeEffectFactory edgeEffectFactory
)
Set a EdgeEffectFactory for this RecyclerView.
When a new EdgeEffectFactory is set, any existing over-scroll effects are cleared and new effects are created as needed using createEdgeEffect
| Parameters | |
|---|---|
@NonNull RecyclerView.EdgeEffectFactory edgeEffectFactory |
The |
setHasFixedSize
public void setHasFixedSize(boolean hasFixedSize)
RecyclerView can perform several optimizations if it can know in advance that RecyclerView's size is not affected by the adapter contents. RecyclerView can still change its size based on other factors (e.g. its parent's size) but this size calculation cannot depend on the size of its children or contents of its adapter (except the number of items in the adapter).
If your use of RecyclerView falls into this category, set this to true. It will allow RecyclerView to avoid invalidating the whole layout when its adapter contents change.
| Parameters | |
|---|---|
boolean hasFixedSize |
true if adapter changes cannot affect the size of the RecyclerView. |
setItemAnimator
public void setItemAnimator(@Nullable RecyclerView.ItemAnimator animator)
Sets the ItemAnimator that will handle animations involving changes to the items in this RecyclerView. By default, RecyclerView instantiates and uses an instance of DefaultItemAnimator. Whether item animations are enabled for the RecyclerView depends on the ItemAnimator and whether the LayoutManager supports item animations.
| Parameters | |
|---|---|
@Nullable RecyclerView.ItemAnimator animator |
The ItemAnimator being set. If null, no animations will occur when changes occur to the items in this RecyclerView. |
setItemViewCacheSize
public void setItemViewCacheSize(int size)
Set the number of offscreen views to retain before adding them to the potentially shared recycled view pool.
The offscreen view cache stays aware of changes in the attached adapter, allowing a LayoutManager to reuse those views unmodified without needing to return to the adapter to rebind them.
| Parameters | |
|---|---|
int size |
Number of views to cache offscreen before returning them to the general recycled view pool |
public void setLayoutFrozen(boolean frozen)Enable or disable layout and scroll. After setLayoutFrozen(true) is called, Layout requests will be postponed until setLayoutFrozen(false) is called; child views are not updated when RecyclerView is frozen, smoothScrollBy, scrollBy, scrollToPosition and smoothScrollToPosition are dropped; TouchEvents and GenericMotionEvents are dropped; onFocusSearchFailed will not be called.
setLayoutFrozen(true) does not prevent app from directly calling scrollToPosition, smoothScrollToPosition.
setAdapter and swapAdapter will automatically stop frozen.
Note: Running ItemAnimator is not stopped automatically, it's caller's responsibility to call ItemAnimator.end().
| Parameters | |
|---|---|
boolean frozen |
true to freeze layout and scroll, false to re-enable. |
setLayoutManager
public void setLayoutManager(@Nullable RecyclerView.LayoutManager layout)
Set the LayoutManager that this RecyclerView will use.
In contrast to other adapter-backed views such as android.widget.ListView or android.widget.GridView, RecyclerView allows client code to provide custom layout arrangements for child views. These arrangements are controlled by the LayoutManager. A LayoutManager must be provided for RecyclerView to function.
Several default strategies are provided for common uses such as lists and grids.
| Parameters | |
|---|---|
@Nullable RecyclerView.LayoutManager layout |
LayoutManager to use |
setOnFlingListener
public void setOnFlingListener(
@Nullable RecyclerView.OnFlingListener onFlingListener
)
Set a OnFlingListener for this RecyclerView.
If the OnFlingListener is set then it will receive calls to fling and will be able to intercept them.
| Parameters | |
|---|---|
@Nullable RecyclerView.OnFlingListener onFlingListener |
The |
public voidsetOnScrollListener(@Nullable RecyclerView.OnScrollListener listener)
Set a listener that will be notified of any changes in scroll state or position.
| Parameters | |
|---|---|
@Nullable RecyclerView.OnScrollListener listener |
Listener to set or null to clear |
setPreserveFocusAfterLayout
public void setPreserveFocusAfterLayout(boolean preserveFocusAfterLayout)
Set whether the RecyclerView should try to keep the same Item focused after a layout calculation or not.
Usually, LayoutManagers keep focused views visible before and after layout but sometimes, views may lose focus during a layout calculation as their state changes or they are replaced with another view due to type change or animation. In these cases, RecyclerView can request focus on the new view automatically.
| Parameters | |
|---|---|
boolean preserveFocusAfterLayout |
Whether RecyclerView should preserve focused Item during a layout calculations. Defaults to true. |
| See also | |
|---|---|
getPreserveFocusAfterLayout |
setRecycledViewPool
public void setRecycledViewPool(@Nullable RecyclerView.RecycledViewPool pool)
Recycled view pools allow multiple RecyclerViews to share a common pool of scrap views. This can be useful if you have multiple RecyclerViews with adapters that use the same view types, for example if you have several data sets with the same kinds of item views displayed by a androidx.viewpager.widget.ViewPager.
| Parameters | |
|---|---|
@Nullable RecyclerView.RecycledViewPool pool |
Pool to set. If this parameter is null a new pool will be created and used. |
public voidsetRecyclerListener(@Nullable RecyclerView.RecyclerListener listener)
Register a listener that will be notified whenever a child view is recycled.
This listener will be called when a LayoutManager or the RecyclerView decides that a child view is no longer needed. If an application associates expensive or heavyweight data with item views, this may be a good place to release or free those resources.
| Parameters | |
|---|---|
@Nullable RecyclerView.RecyclerListener listener |
Listener to register, or null to clear |
setScrollingTouchSlop
public void setScrollingTouchSlop(int slopConstant)
Configure the scrolling touch slop for a specific use case. Set up the RecyclerView's scrolling motion threshold based on common usages. Valid arguments are TOUCH_SLOP_DEFAULT and TOUCH_SLOP_PAGING.
| Parameters | |
|---|---|
int slopConstant |
One of the |
setVerboseLoggingEnabled
public static void setVerboseLoggingEnabled(boolean verboseLoggingEnabled)
Enable verbose logging within RecyclerView itself.
Enabling this may negatively affect performance and reduce the utility of logcat due to high-volume logging. This generally should not be enabled in production unless you have a specific reason for doing so.
| Parameters | |
|---|---|
boolean verboseLoggingEnabled |
true to enable logging; false to disable it |
setViewCacheExtension
public void setViewCacheExtension(
@Nullable RecyclerView.ViewCacheExtension extension
)
Sets a new ViewCacheExtension to be used by the Recycler.
| Parameters | |
|---|---|
@Nullable RecyclerView.ViewCacheExtension extension |
ViewCacheExtension to be used or null if you want to clear the existing one. |
| See also | |
|---|---|
getViewForPositionAndType |
smoothScrollBy
public void smoothScrollBy(@Px int dx, @Px int dy)
Animate a scroll by the given amount of pixels along either axis.
smoothScrollBy
public void smoothScrollBy(@Px int dx, @Px int dy, @Nullable Interpolator interpolator)
Animate a scroll by the given amount of pixels along either axis.
| Parameters | |
|---|---|
@Px int dx |
Pixels to scroll horizontally |
@Px int dy |
Pixels to scroll vertically |
@Nullable Interpolator interpolator |
|
smoothScrollBy
public void smoothScrollBy(
@Px int dx,
@Px int dy,
@Nullable Interpolator interpolator,
int duration
)
Smooth scrolls the RecyclerView by a given distance.
| Parameters | |
|---|---|
@Px int dx |
x distance in pixels. |
@Px int dy |
y distance in pixels. |
@Nullable Interpolator interpolator |
|
int duration |
Duration of the animation in milliseconds. Set to |
smoothScrollToPosition
public void smoothScrollToPosition(int position)
Starts a smooth scroll to an adapter position.
To support smooth scrolling, you must override smoothScrollToPosition and create a SmoothScroller.
LayoutManager is responsible for creating the actual scroll action. If you want to provide a custom smooth scroll logic, override smoothScrollToPosition in your LayoutManager.
| Parameters | |
|---|---|
int position |
The adapter position to scroll to |
| See also | |
|---|---|
smoothScrollToPosition |
startNestedScroll
public boolean startNestedScroll(int axes, int type)
Begin a nestable scroll operation along the given axes, for the given input type.
A view starting a nested scroll promises to abide by the following contract:
The view will call startNestedScroll upon initiating a scroll operation. In the case of a touch scroll type this corresponds to the initial ACTION_DOWN. In the case of touch scrolling the nested scroll will be terminated automatically in the same manner as requestDisallowInterceptTouchEvent. In the event of programmatic scrolling the caller must explicitly call stopNestedScroll to indicate the end of the nested scroll.
If startNestedScroll returns true, a cooperative parent was found. If it returns false the caller may ignore the rest of this contract until the next scroll. Calling startNestedScroll while a nested scroll is already in progress will return true.
At each incremental step of the scroll the caller should invoke dispatchNestedPreScroll once it has calculated the requested scrolling delta. If it returns true the nested scrolling parent at least partially consumed the scroll and the caller should adjust the amount it scrolls by.
After applying the remainder of the scroll delta the caller should invoke dispatchNestedScroll, passing both the delta consumed and the delta unconsumed. A nested scrolling parent may treat these values differently. See onNestedScroll.
| Parameters | |
|---|---|
int axes |
Flags consisting of a combination of |
int type |
the type of input which cause this scroll event |
| Returns | |
|---|---|
boolean |
true if a cooperative parent was found and nested scrolling has been enabled for the current gesture. |
stopNestedScroll
public void stopNestedScroll(int type)
Stop a nested scroll in progress for the given input type.
Calling this method when a nested scroll is not currently in progress is harmless.
| Parameters | |
|---|---|
int type |
the type of input which cause this scroll event |
| See also | |
|---|---|
startNestedScroll |
stopScroll
public void stopScroll()
Stop any current scroll in progress, such as one started by smoothScrollBy, fling or a touch-initiated fling.
suppressLayout
public final void suppressLayout(boolean suppress)
Tells this RecyclerView to suppress all layout and scroll calls until layout suppression is disabled with a later call to suppressLayout(false). When layout suppression is disabled, a requestLayout() call is sent if requestLayout() was attempted while layout was being suppressed.
In addition to the layout suppression smoothScrollBy, scrollBy, scrollToPosition and smoothScrollToPosition are dropped; TouchEvents and GenericMotionEvents are dropped; onFocusSearchFailed will not be called.
suppressLayout(true) does not prevent app from directly calling scrollToPosition, smoothScrollToPosition.
setAdapter and swapAdapter will automatically stop suppressing.
Note: Running ItemAnimator is not stopped automatically, it's caller's responsibility to call ItemAnimator.end().
| Parameters | |
|---|---|
boolean suppress |
true to suppress layout and scroll, false to re-enable. |
swapAdapter
public void swapAdapter(
@Nullable RecyclerView.Adapter adapter,
boolean removeAndRecycleExistingViews
)
Swaps the current adapter with the provided one. It is similar to setAdapter but assumes existing adapter and the new adapter uses the same ViewHolder and does not clear the RecycledViewPool.
Note that it still calls onAdapterChanged callbacks.
| Parameters | |
|---|---|
@Nullable RecyclerView.Adapter adapter |
The new adapter to set, or null to set no adapter. |
boolean removeAndRecycleExistingViews |
If set to true, RecyclerView will recycle all existing Views. If adapters have stable ids and/or you want to animate the disappearing views, you may prefer to set this to false. |
| See also | |
|---|---|
setAdapter |
Protected methods
dispatchRestoreInstanceState
protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container)
Override to prevent thawing of any views created by the adapter.
dispatchSaveInstanceState
protected void dispatchSaveInstanceState(SparseArray<Parcelable> container)
Override to prevent freezing of any views created by the adapter.
generateLayoutParams
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
onRequestFocusInDescendants
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)