-
Notifications
You must be signed in to change notification settings - Fork 553
5.x | ViewHolders
- FlexibleViewHolder
- ExpandableViewHolder
- Create/Binding ViewHolders
- Method A (new!)
- Method B (classic)
FlexibleViewHolder
is responsible for the View activation and for the 4 events, it handles the ClickListener, OnLongClickListener, OnTouchListener (drag and swipe actions).
To be continued...
ExpandableViewHolder
extends FlexibleViewHolder
.
Here we handle the events to expand/collapse an item.
To be continued...
Via Item interfaces. In this case you don't need to implement getItemViewType()
, onCreateViewHolder()
and onBindViewHolder()
adapter methods, but getLayoutRes()
, createViewHolder()
and bindViewHolder()
from inside the implementation of item interfaces (for the item type we need an int
, the layoutResID is sufficient) .
Adopting item interfaces, it gives several benefits such as: Expandable items, runtime flags to enable/disable drag and swipe, to enable/disable the item itself and to allow/disallow the selection.
@Override
public int getLayoutRes() {
return R.layout.recycler_expandable_row;
}
@Override
public ViewHolder createViewHolder(FlexibleAdapter adapter, LayoutInflater inflater, ViewGroup parent) {
return new ViewHolder(inflater.inflate(getLayoutRes(), parent, false), adapter);
}
@Override
public void bindViewHolder(final FlexibleAdapter adapter, ViewHolder holder, int position, List payloads) {
//Bind your VH
}
The ViewHolder
class is an inner static class of the same item interface.
You override and implement getItemViewType()
, onCreateViewHolder()
and onBindViewHolder()
adapter methods as usual.
Note: If you don't want to adopt item interfaces, you have to override the 3 Adapter methods, otherwise the Adapter enters in auto-mapping mode dedicated for item interfaces!
For multiple view types you still need to add a switch
statement in the 3 methods and cast the specific item where necessary.
A difference with others libraries, is that you don't have different names for Creation and Binding methods, because you have item interfaces, therefore, the method B is become (in my opinion) obsolete in case of multiple types, but it can still be used in case of 1 type.
ViewHolders are as well defined all in the same Adapter class.
To be continued...
- Update Data Set
- Selection modes
- Headers and Sections
- Scrollable Headers and Footers
- Expandable items
- Drag&Drop and Swipe
- EndlessScroll / On Load More
- Search Filter
- FastScroller
- Adapter Animations
- Third party Layout Managers
- Payload
- Smooth Layout Managers
- Flexible Item Decoration
- Utils
- ActionModeHelper
- AnimatorHelper
- EmptyViewHelper
- UndoHelper
* = Under revision!