Skip to content
Davide Steduto edited this page Jul 22, 2016 · 22 revisions

In this page

  • FlexibleViewHolder
  • ExpandableViewHolder
  • Create/Binding ViewHolders
    • Method A (new!)
    • Method B (classic)

FlexibleViewHolder

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

ExpandableViewHolder extends FlexibleViewHolder. Here we handle the events to expand/collapse an item.

To be continued...

Create/Binding ViewHolders

Method A (new!)

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.

Method B (classic)

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...

Clone this wiki locally