13

Im at a bit of loss on this one on how to produce sections in a ListView when you use both Cursors and a Custom SimpleCursorAdapter.

Many of the docs out there reference using getView() etc, or creating several Adapters and adding section headers.

But these all appear to be based on BaseAdapters, ListAdapters, and ArrayAdapters etc.

Has anybody dealt with anything similar previously?

If not, any tips on how to make this work?

Thanks Simon

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Simon
  • 1,385
  • 1
  • 11
  • 20

2 Answers2

9

If you're using a CursorAdapter, you can use my SectionCursorAdapter.

monxalo
  • 581
  • 5
  • 14
  • Cheers, this worked great with SimpleCursorAdapters to have alphabetized sections in my ListView. This was a lot more work than I thought, I think SimpleCursorAdapter spoiled me in it's simplicity! – georgiecasey Aug 22 '12 at 15:17
  • 1
    It's not efficient for the database SimpleCursorAdapter with long list of items since you have to iterate over all the items to calculate the header. If the cursor is returned with a GROUP BY query then it's a lot better to compare the header (the grouped value) of the current item agains that of the previous & next items to determine if we have a new section or not. – Phi Van Ngoc Apr 30 '14 at 10:56
  • You may want to use AlphabetIndexer for calculating sections. – ycagri Apr 14 '16 at 15:27
2

Another great one which is in active development is SectionCursorAdapter and it supports gradle. The creator of the it has also promised that it will be updated to support RecyclerView when it is officially released. You can also check out the blog post about it at ToastDroid

MinceMan
  • 7,483
  • 3
  • 38
  • 40