0

I'm trying to make list of items, where each item may have other item with a value connected to it. Something like:

  • Item 1
  • **SubItem1.1 - val1
  • **SubItem1.2 - val2
  • Item 2
  • **SubItem2.1 - val3
  • Item3
  • **SubItem3.1 - val4
  • **SubItem3.2 - val5
  • **SubItem3.3 - val6

There might be a dynamic number of Items and a dynamic number of Sub-items for each Item. There is always one value for each subitem. The Items, subItems and values are found from a database, but there are an alogrithm with calculations to get the correct subitems and values for each Item, so I do not think I can use a SimpleCursorAdapter directly.

How should I write this adapter and what should the xml-files look like. Do I need two xml-files with ListView? (Since there basically are two lists? (One with Items, and one list for each Item with Sub-items/values))

EirikO
  • 617
  • 8
  • 19
  • 2
    You could use an [ExpandableListView](http://developer.android.com/reference/android/widget/ExpandableListView.html). – Sam Jan 13 '13 at 20:47

1 Answers1

0

If your data comes from a Cursor, this implentation looks interesting. Otherwise, this implementation works fine.

And finally, there is one you can get from RoboSpice motivations repo : for a more static data set.

You should only take great care, inside you getView method to use the recycled pool of views and to avoid instanciating too many objects. To avoid using instanceof (as it is costly) to test the recycled views, you must use getViewTypeCount and getViewType correctly.

Snicolas
  • 37,840
  • 15
  • 114
  • 173