AndreiBogdan
AndreiBogdan

Reputation: 11174

Add subheaders in GridView

I would like to add empty rows between GridView rows (not cells, but rows) and in these empty spaces I'd like to add text, so basically add subheaders for sections in the GridView.

Something like this:

Subheader 1
cell cell cell cell
cell cell cell cell
Subheader 2
cell cell cell cell
cell cell
Subheader 3
cell cell cell cell
cell
.......

Can't find a way of doing this. Any ideas?

Upvotes: 0

Views: 580

Answers (2)

Tamilselvan Kalimuthu
Tamilselvan Kalimuthu

Reputation: 1532

Sticky Grid header

Here is a link - sticky list header for ur requirement, header for each group of grid items. Try it.

Upvotes: 2

Harshit Rathi
Harshit Rathi

Reputation: 1862

I think this is possible by making your own layout:

<ScrollView>
  <LinearLayout android:id="@+id/container">
    <com.project.MyGridView/>
  </LinearLayout>
</ScrollView>

To add header use something like that:

container.addView(header, 0);

and last you must expand GridView height:

Class MyGridView extends GridView {
    ....
    @Override
    protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, MeasureSpec.UNSPECIFIED);
    }
    ....
}

Upvotes: 1

Related Questions