I have been using cursor along with recyclerview.
I have a queried cursor object (passed from loader) and an array of header Strings[].
String headers[] = {"apples", "bananas"...};
Now I want to show items as
Apples
cursor row 1
cursor row 2
cursor row 3
Bananas
cursor row 4
cursor row 5
I don't want to tweak with getItemCount() method. So, planning to pass a single cursor with proper length.
One possible way is to use MatrixCursor and MergeCursor to add dummy rows as mentioned here: Adding rows into Cursor manually. This is fine but MergeCursor aligns headers and cursor data one after the other.
Wanted to explore ways in which a final cursor can be achieved with the correct header and item positions.
You can use the library SectionedRecyclerViewAdapter to group your data into sections and add a header to each section.
First create a Section class:
Then you set up the RecyclerView with your Sections:
With the example above you will have to work on how to convert your
Cursor
intoList<String>
but you can change the MySection class to receive aCursor
instead of aList<String>
.