GridView with section headers

10,396

This is not strictly possible. GridView does everything in terms of cells.

Now, you are welcome to create a set of cells that, when displayed together in a row, happen to look like a header. Presumably my MergeAdapter can handle that, though I have certainly never tried it. It will be up to you to ensure that:

  • the header cells are all in one row, which implies that...
  • empty cells go in any spaces in the preceding row, after the last "real" cell and before your header cells, and...
  • that you have the right number of header cells (i.e., equal to your number of columns), and...
  • that the header cells render correctly to look like a contiguous header, and...
  • that you use areAllItemsEnabled() and isEnabled() correctly, so that the header cells and the empty cells are not enabled
Share:
10,396
Sandeep Chayapathi
Author by

Sandeep Chayapathi

I'm Head of Engineering at Bulletin.co

Updated on November 04, 2022

Comments

  • Sandeep Chayapathi
    Sandeep Chayapathi over 1 year

    Im trying to implement a GridView with section headers. I found one other question here Android GridView with categories? , however following the accepted answer gives me "header" as cells instead of the header being in its own row.

    Im not sure what Im missing here (have tried the MergeAdapter too), can someone point out the nuance thats needed to implement the section headers in a GridView ?