I have a recyclerview that shows items that were bought and to be bought. The items are sorted by purchase date which can be in the past and future.
I want to add a separator between the last "past" item and the first "future" one. I know I should add a decorator like the following:
DividerItemDecoration decoration = new DividerItemDecoration(Objects.requireNonNull(getActivity()), VERTICAL);
rvItems.addItemDecoration(decoration);
The decorator is a thin horizontal line that is shown between all items. How can I make the decorator a text, something like "↓ past items ↑ future items" and to be visible only between the relevant items?
Thanks
In such a case I think it is preferable to have a recycler view adapter that supports multiple types of items.
The
separators
that you call, will besections
Example:
Adapter:
Then create the corresponding
ViewHolders
for eachtype
and instantiate them atonCreateViewHolder
.And when you pass the list of Items in the adapter you should have logic that adds either a Section or an Item to the list.
Similar example from one of my projects:
I suggest taking a look at this library to quickly make lists with different item types.