0

I have list of Items from database ordered by rooms:

List<Item> items = database.getAllItemsOrderedByRoom();

Every item has roomID, and few other properties.

And I have CustomItemsArrayAdapter which now works with items but doesn't create headers.

What I want to do is to create list not only with items, but also with room headers based on values passed inside items. So it would work like:

Long actualRoom = null;
for(Item item : items){
    Long itemRoom = item.getRoom;
    if(itemRoom != actualRoom){
         actualRoom = itemRoom;
         list.putRoomHeader(actualRoom);
         list.putItem(item);
    } else { 
         list.putItem(item);
    }
}

I would like to have this working inside CustomItemsArrayAdapter after using constructor: adapter = new CustomItemsArrayAdapter(context, items); I stumbled upon very good explanation how to do headers: Android ListView headers , but it makes me prepare values list before creating adapter and that is unconvenient if I use few similar lists in my app.

Is there a way of processing values inside constructor of CostomItemsArrayAdapter?

Community
  • 1
  • 1
Rafał Praczyk
  • 431
  • 7
  • 16

1 Answers1

0

Use Expandable list view,

visit http://developer.android.com/reference/android/widget/ExpandableListAdapter.html

Use Groupview as section.

Shiva
  • 39
  • 3