Type Parameters:
VB - The type of the dynamic recycler view binder.
Direct Known Subclasses:
DynamicSimpleBinderAdapter, DynamicTypeBinderAdapter

public abstract class DynamicBinderAdapter<VB extends DynamicRecyclerViewBinder> extends DynamicRecyclerViewAdapter<RecyclerView.ViewHolder>
A RecyclerView.Adapter to display different types of items or views in a recycler view.

Each section can have a header or a completely different item.

Extend this adapter and use DynamicRecyclerViewBinder to create binding logic for the each type of views.

  • Constructor Details

    • DynamicBinderAdapter

      public DynamicBinderAdapter()
  • Method Details

    • onCreateViewHolder

      @NonNull public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
      Specified by:
      onCreateViewHolder in class RecyclerView.Adapter<RecyclerView.ViewHolder>
    • onBindViewHolder

      public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position)
      Specified by:
      onBindViewHolder in class RecyclerView.Adapter<RecyclerView.ViewHolder>
    • getItemCount

      public abstract int getItemCount()
      Specified by:
      getItemCount in class RecyclerView.Adapter<RecyclerView.ViewHolder>
    • getItemViewType

      public abstract int getItemViewType(int position)
      Overrides:
      getItemViewType in class RecyclerView.Adapter<RecyclerView.ViewHolder>
    • getDataBinder

      public abstract VB getDataBinder(int viewType)
      Get data binder according to the view type.
      Parameters:
      viewType - The view type constant to get the data binder.
      Returns:
      The data binder associated with this view type.
      See Also:
    • getPosition

      public abstract int getPosition(@NonNull VB binder, int position)
      Get the position of a data binder item inside the recycler view.
      Parameters:
      binder - The data binder inside the recycler view.
      position - The position of the data binder item.
      Returns:
      The position of the data binder item inside the recycler view.
    • getBinderPosition

      public abstract int getBinderPosition(int position)
      Get the position of a data binder inside the recycler view.
      Parameters:
      position - The position of the data binder.
      Returns:
      The position of the data binder inside the recycler view.
    • notifyBinderDataSetChanged

      public void notifyBinderDataSetChanged()
      This method will be called when the data has been changed.
    • notifyBinderItemChanged

      public void notifyBinderItemChanged(@NonNull VB binder, int position)
      This method will be called when an item has been changed in the data binder.
      Parameters:
      binder - The data binder inside the recycler view.
      position - The position at which the item has been changed.
    • notifyBinderItemInserted

      public void notifyBinderItemInserted(@NonNull VB binder, int position)
      This method will be called when an item has been inserted in the data binder.
      Parameters:
      binder - The data binder inside the recycler view.
      position - The position at which the item is inserted.
    • notifyBinderItemRemoved

      public void notifyBinderItemRemoved(@NonNull VB binder, int position)
      This method will be called when an item has been removed in the data binder.
      Parameters:
      binder - The data binder inside the recycler view.
      position - The position at which the item has been removed.
    • notifyBinderItemMoved

      public void notifyBinderItemMoved(@NonNull VB binder, int fromPosition, int toPosition)
      This method will be called when an item has been moved in the data binder.
      Parameters:
      binder - The data binder inside the recycler view.
      fromPosition - Initial position of the moved item.
      toPosition - Final position of the moved item.
    • notifyBinderItemRangeChanged

      public abstract void notifyBinderItemRangeChanged(@NonNull VB binder, int position, int itemCount)
      This method will be called when the item range of a data binder has been changed.
      Parameters:
      binder - The data binder inside the recycler view.
      position - The position at which the first item has been changed.
      itemCount - Total no. of items have been changed.
    • notifyBinderItemRangeInserted

      public abstract void notifyBinderItemRangeInserted(@NonNull VB binder, int position, int itemCount)
      This method will be called when a set of items have been inserted in a data binder.
      Parameters:
      binder - The data binder inside the recycler view.
      position - The position at which the first item has been inserted.
      itemCount - Total no. of items have been inserted.
    • notifyBinderItemRangeRemoved

      public abstract void notifyBinderItemRangeRemoved(@NonNull VB binder, int position, int itemCount)
      This method will be called when a set of items have been removed in a data binder.
      Parameters:
      binder - The data binder inside the recycler view.
      position - The position at which the first item has been removed.
      itemCount - Total no. of items have been removed.