This library adds header/footer functionality to vertical and horizontal RecyclerView (for all 3 built-in types--linear, staggered-grid, grid) and abstract RecyclerView.Adapter into an interface for easier usage of multiple ViewHolder types.
- App Compat v7: com.android.support:appcompat-v7:21.0.0 or higher
- RecyclerView v7: com.android.support:recyclerview-v7:21.0.0 or higher
- Set up the project dependencies
private List<String> mItems;
public ExampleIntermediary(List<String> items){
mItems=items;
}
@Override
public int getItemCount() {
return mItems.size();
}
@Override
public Object getItem(int position) {
return mItems.get(position);
}
@Override
public RecyclerView.ViewHolder getViewHolder(ViewGroup viewGroup, int type) {
switch (type){
... //based on the type (getItemViewType), return the correct view holder
}
}
@Override
public int getItemViewType(int position) {
return position % 4; //any logic can go here
}
@Override
public void populateViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
switch (getItemViewType(position){
...
}
}
}