0

I am trying to have a specific layout in Android Studio : I want to display a list of objects which have to be separated by a date. For the moment, I'm only able to display a list of all my objects but I can't figure out how to organize my layout to have them split.

Here are some images to help you understand :

What I have for the moment

What I would like to have

Let's say the objects I want to display have 2 attributes : date and content. Thanks to a ListView, I'm able to display the content attributes of all my objects. (all my objects are in an ArrayList which are put into the ListView thanks to an adapter)

The thing is I can't think of a correct architecture to display a date, then all the objects that have this date as their date attribute, then another date, all the objects that have that other date as their date attribute, and so on ...

A solution I thought of was to have a ListView of ListViews, the latter containing objects that would have 2 attributes : a date and a list of the objects. But doing that, I'm a bit lost with the adapters.

I don't know if I'm being clear enough, please let me know if you need further info to help me out

Thank you in advance !

YumHax
  • 19
  • 7

1 Answers1

0

You can have an arraylist populated as {"01/01/2016", "item1", "item2", "02/01/2016", "item3", "item4", ...}

Then, when you populate your single item view with item data you can try to parse a date. If parsing go well => you are processing a date header, so you can set bold text and borders. Else you are managing a simple data item, so you can simply show it.

Keep in mind view recycling, as you set bold and borders on date items, you must unset them on simple items.

However you should use a RecyclerView

firegloves
  • 5,581
  • 2
  • 29
  • 50