1

i have to make a sectioned list in my application. For this i am using the following approach:

  • make a listview to contain the headers of each sections
  • the xml inflated in the getview of each item in the above list consists of a textview and a tablelayout
  • the custom adapter used to make the views for the above listview, i fill the textview with the header and add rows into the tablelayout until all the section is filled.

Naturally i maintain two arrays: 1) for the headers 2) for the section details(actually for this i use a hashmap with the section header index in its array as the key, this is my of identifying which header belongs to which section).

for some reason the above code is not working and the data is being repeated in different sections...eg. the second section contains data of the 1st and the 2nd section combined?

why is this happening?

Doesn't the idea mentioned above seem correct?

what is going wrong over here?

thank you in advance.

user590849
  • 11,655
  • 27
  • 84
  • 125

1 Answers1

2

For hierarchical data structures you should rather use ExpandableListView/ExpandableListActivity then ListView (see this example for reference).

This way you'll use a BaseExpandableListAdapter to populate your list, which has two methods for the renderers:

  • getGroupView should be overridden for the headers,
  • getChildView should be overridden for the child items of the different headers

If you don't need your list to be collapsable/expandable, you set all of your groups expanded, and disable collapsing as described here.

Community
  • 1
  • 1
rekaszeru
  • 19,130
  • 7
  • 59
  • 73