0

I'm an android dev beginner and I know the basics of a simple list view.

But what I need to do now is (I think) pretty advanced, so please tell me how (or if?) this is possible:

I have different dates and for each date, a different set (even a different count) of attributes. These attributes are created by the user dynamically. This is the structure:

07.09.2012 - Weight: 10
07.09.2012 - Fat: 20
07.09.2012 - Muscles: 30

08.09.2012 - Weight: 20

09.09.2012 - Weight: 30
09.09.2012 - Water: 10

etc.

I need to present this information in a clearly arranged / simple way, so I thought about a custom listview which could look like:

LIST:

07.09.2012
+ Weight: 10
+ Fat: 20
+ Muscles: 30
08.09.2012
+ Weight: 20
09.09.2012
+ Weight: 30
+ Water: 10

It would be event better if only dates are shown first and the additional information below the date is collapsed but expandable.

Is this possible? Can you point me to some code examples / provide me some code? IF this is not possible or hard, or you have a better idea of visualizing this dynamic information, can you tell me a better way?

Thanks!

Toni Kanoni
  • 2,265
  • 4
  • 23
  • 29

1 Answers1

1

You are probably looking for ExpandableListView . Here is an example how to use it.

If you don't want/need expanding and collapsing you can create a Layout for the items (in your case the date) and you can set the visibility for things not shown for the date (e.g. Water) to View.GONE. This way they won't take any space on the screen.

Lastly, you could simply use a ScrollView and put all the items in there. This, is however only acceptable if you know you will not have a lot of items, because ListView is optimized.

stoilkov
  • 1,686
  • 1
  • 11
  • 18
  • Hmmm seems like the expandable list is exactly what I want! So each attribute is a child under the date, and it doesn't matter how many and which children are there for a date, right? Now I just have to figure out how to use this with data coming from an SQLite db. Thanks! – Toni Kanoni Sep 07 '12 at 08:55