Skip to content Skip to sidebar Skip to footer

How To Insert Header Row On Expandable List View

I have an Android activity with one expandable list view. Then I have created my ExpandableListAdapter, so I can click on one items and I can see the child of this item. This is ok

Solution 1:

You cam easily add header to expandablelistview by using the code below :

View header=getLayoutInflater().inflate(R.layout.nav_header, null);
 mExpandableListView.addHeaderView(header);

Just copy the above code in your activity. In the above code (R.layout.nav_header) is the xml file of header and mExpandableListView is the object of ExpandableListView.

Solution 2:

You are right. In order to add Header and footer to expandableListview, you can do some modifications.

getChildrenCount() method returns the count of row of child item in a specific group. Here we can add two extra rows to the return method. The first row will be used for header and the second row will be used for footer. and we can inflate the specific layout to first(header) and last row(footer) of a group.

Post a Comment for "How To Insert Header Row On Expandable List View"