I am trying to implement subheaders inside my RecyclerView . As an adapter for my RecyclerView , I use the PagedListAdapter from the new Paging Library with the Room combination.
Data coming from the database contains dates. I want to split / group items by day and show the date inside the subtitle.
What would be the best way to implement subheaders with this combination? AFAIK, it is not possible to implement this βstandardβ ViewType because it will replace the first element of the data list with a header. I'm currently trying to accomplish this using RecyclerView.ItemDecoration , but I cannot get it to work.
Can someone point me in the right direction?
So far my RecyclerView.ItemDecoration :
public class RecyclerViewHeaderItemDecoration extends RecyclerView.ItemDecoration { private RecyclerViewHeaderReceiver receiver; public RecyclerViewHeaderItemDecoration setReceiver(RecyclerViewHeaderReceiver receiver) { this.receiver = receiver; return this; } @Override public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { final int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { if (receiver != null) { View view = parent.getChildAt(i); int position = parent.getChildAdapterPosition(view); int previousPosition = position - 1; if (position == 0 || (position != RecyclerView.NO_POSITION && receiver.isNewSection(previousPosition, position))) { ViewHolder headerView = receiver.getSectionHeaderViewHolder(position); parent.getAdapter().bindViewHolder(headerView, position);
source share