public abstract class FlexibleViewHolder extends RecyclerView.ViewHolder implements android.view.View.OnClickListener, android.view.View.OnLongClickListener, android.view.View.OnTouchListener, ItemTouchHelperCallback.ViewHolderCallback
You must extend and implement this class for the own ViewHolder.
| Modifier and Type | Field and Description |
|---|---|
protected int |
mActionState |
protected FlexibleAdapter |
mAdapter |
| Constructor and Description |
|---|
FlexibleViewHolder(android.view.View view,
FlexibleAdapter adapter)
Default constructor.
|
FlexibleViewHolder(android.view.View view,
FlexibleAdapter adapter,
boolean stickyHeader)
Constructor to configure the sticky behaviour of a view.
|
| Modifier and Type | Method and Description |
|---|---|
float |
getActivationElevation()
Allows to set elevation while the view is activated.
|
android.view.View |
getContentView()
In case this ViewHolder represents a Header Item, this method returns the contentView of the
FrameLayout, otherwise it returns the basic itemView.
|
int |
getFlexibleAdapterPosition()
Overcomes the situation of returning an unknown position (-1) of ViewHolders created out of
the LayoutManager (ex.
|
android.view.View |
getFrontView()
On Swipe, override to return the Front View.
|
android.view.View |
getRearLeftView()
On Swipe, override to return the Rear Left View.
|
android.view.View |
getRearRightView()
On Swipe, override to return the Rear Right View.
|
boolean |
isDraggable() |
boolean |
isSwipeable() |
void |
onActionStateChanged(int position,
int actionState)
Here we handle the event of when the
ItemTouchHelper first registers an item
as being moved or swiped. |
void |
onClick(android.view.View view) |
void |
onItemReleased(int position)
Here we handle the event of when the ItemTouchHelper has completed the move or swipe.
|
boolean |
onLongClick(android.view.View view) |
boolean |
onTouch(android.view.View view,
android.view.MotionEvent event)
Should be used only by the Handle View!
|
void |
scrollAnimators(java.util.List<android.animation.Animator> animators,
int position,
boolean isForward)
This method is automatically called by FlexibleAdapter to animate the View while the user
actively scrolls the list (forward or backward).
|
void |
setBackupPosition(int backupPosition)
Restore the Adapter position if the original Adapter position is unknown.
|
protected void |
setDragHandleView(android.view.View view)
Sets the inner view which will be used to drag this itemView.
|
void |
setFullSpan(boolean enabled)
Support for StaggeredGridLayoutManager.
|
protected boolean |
shouldActivateViewWhileSwiping()
Allows to activate the itemView when Swipe event occurs.
|
protected boolean |
shouldAddSelectionInActionMode()
Allows to add and keep item selection if ActionMode is active.
|
void |
toggleActivation()
Allows to change and see the activation status on the itemView and to perform animation
on inner views.
|
protected final FlexibleAdapter mAdapter
protected int mActionState
public FlexibleViewHolder(android.view.View view,
FlexibleAdapter adapter)
view - The View being hosted in this ViewHolderadapter - Adapter instance of type FlexibleAdapterpublic FlexibleViewHolder(android.view.View view,
FlexibleAdapter adapter,
boolean stickyHeader)
Note: StickyHeader works only if the item has been declared of type
IHeader.
view - The View being hosted in this ViewHolderadapter - Adapter instance of type FlexibleAdapterstickyHeader - true if the View can be a Sticky Header, false otherwisepublic void onClick(android.view.View view)
onClick in interface android.view.View.OnClickListenertoggleActivation()public boolean onLongClick(android.view.View view)
onLongClick in interface android.view.View.OnLongClickListenertoggleActivation()public boolean onTouch(android.view.View view,
android.view.MotionEvent event)
onTouch in interface android.view.View.OnTouchListenersetDragHandleView(View)public void setFullSpan(boolean enabled)
enabled - true to enable full span size, false to disableprotected void setDragHandleView(android.view.View view)
view - handle viewonTouch(View, MotionEvent)public void toggleActivation()
Important note! the selected background is visible if you added
android:background="?attr/selectableItemBackground" in the item layout AND
customized the file style.xml.
DrawableUtils from UI extension.
Note: This method must be called every time we want the activation state visible on the itemView, for instance: after a Click (to add the item to the selection list) or after a LongClick (to activate the ActionMode) or during dragging (to show that we enabled the Drag).
If you follow the above instructions, it's not necessary to invalidate this view withnotifyItemChanged: In this way bindViewHolder won't be called and inner
views can animate without interruptions, eventually you will see the animation running
on those inner views at the same time of selection activation.getActivationElevation()public float getActivationElevation()
Override to return desired value of elevation on this itemView.
Note: returned value must be in Pixel.0px (never elevate) if not overriddentoggleActivation()protected boolean shouldActivateViewWhileSwiping()
This method returns always false; Override with "return true" to Not expand or
collapse this itemView onClick events.
toggleActivation()protected boolean shouldAddSelectionInActionMode()
This method returns always false;Override with "return true" to add the item
to the ActionMode count.
toggleActivation()public void scrollAnimators(java.util.List<android.animation.Animator> animators,
int position,
boolean isForward)
Implement your logic for different animators based on position, selection and/or direction.
Use can take one of the predefined Animator from package UI classAnimatorHelper
or create your own Animator(s), then add it to the list of animators.animators - NonNull list of animators, which you should add new animatorsposition - can be used to differentiate the Animators based on positionsisForward - can be used to separate animation from top/bottom or from left/right scrollingpublic void onActionStateChanged(int position,
int actionState)
ItemTouchHelper first registers an item
as being moved or swiped.
In this implementation, View activation is automatically handled if dragged: The Item will be added to the selection list if not selected yet and mode MULTI is activated.
onActionStateChanged in interface ItemTouchHelperCallback.ViewHolderCallbackposition - the position of the item touchedactionState - one of ItemTouchHelper#ACTION_STATE_SWIPE or
ItemTouchHelper#ACTION_STATE_DRAG.shouldActivateViewWhileSwiping(),
shouldAddSelectionInActionMode()public void onItemReleased(int position)
In this implementation, View activation is automatically handled.
In case of Drag, the state will be cleared depends by current selection mode!onItemReleased in interface ItemTouchHelperCallback.ViewHolderCallbackposition - the position of the item releasedshouldActivateViewWhileSwiping(),
shouldAddSelectionInActionMode()public final boolean isDraggable()
isDraggable in interface ItemTouchHelperCallback.ViewHolderCallbackpublic final boolean isSwipeable()
isSwipeable in interface ItemTouchHelperCallback.ViewHolderCallbackpublic android.view.View getFrontView()
ItemTouchHelperCallback.ViewHolderCallbackDefault is itemView.
getFrontView in interface ItemTouchHelperCallback.ViewHolderCallbackpublic android.view.View getRearLeftView()
ItemTouchHelperCallback.ViewHolderCallbackDefault is null (no view).
getRearLeftView in interface ItemTouchHelperCallback.ViewHolderCallbackpublic android.view.View getRearRightView()
ItemTouchHelperCallback.ViewHolderCallbackDefault is null (no view).
getRearRightView in interface ItemTouchHelperCallback.ViewHolderCallbackpublic final android.view.View getContentView()
public final int getFlexibleAdapterPosition()
NOTE: Always call this method, instead of getAdapterPosition(), in case
of StickyHeaders use case.
#getAdapterPosition() OR the backup position
preset and known, if the previous result was RecyclerView#NO_POSITION.setBackupPosition(int)public final void setBackupPosition(int backupPosition)
Called by StickyHeaderHelper to support the clickListeners events.
backupPosition - the known position of this ViewHolder