You can add a footer as the last element of the RecyclerView itself. You can select a new RecyclerItem class with the isFooter boolean field, wrap all the items in it, put it in an array, and add recyclerItem with isFooter = true at the end. Use the resulting array to initialize the adapter. Then you need to describe an alternative layout for the footer, for example footer_item.xml and override the adapter's getItemViewType () like:
@Override public int getItemViewType(int position) { return items.get(position).isFooter ? 1 : 0; }
in the onCreateViewHolder () of the adapter, enter a condition under which, if the viewType of the element is 1 (isFooter == true), bind the corresponding layout to the holder:
@Override public RecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { RelativeLayout itemLayout; switch (viewType) { case 0: itemLayout = (RelativeLayout)LayoutInflater.from(parent.getContext()) .inflate(R.layout.task_item, parent, false); break; case 1: itemLayout = (RelativeLayout)LayoutInflater.from(parent.getContext()) .inflate(R.layout.footer_item, parent, false); } return new ViewHolder(itemLayout, viewType); }
Well, in onBindViewHolder () it is similar to linking data depending on the type of element:
@Override public void onBindViewHolder(ViewHolder holder, int position) { switch (holder.viewType) { case 0: //для обычного элемента break; case 1: //для футера } }