1

I have a List of custom objects. These objects holds reservation information for the past 2 years (for each day). It is a really big list with about 730 (365+365) items.

I have also a grid view with day cells (like calendar) and i want to draw different things in each day if they meet certain conditions.

The problem is that for each cell in getView i have to loop this large list.

   @Override
public View getView(int position, View convertView, ViewGroup parent)
{
    ...

     String date = dateList.get(position).getDate();
     for(Reservation item: reallyBigList){
           if(item.getDate.equals(date)){
                ...
              break;
            }
     }

    ...
}

This approach make my list very laggy. I am looking for a most efficient way to accomplish this. One solution i can think is to split this large list. But i want to know if there is any other way.

p. leo
  • 48
  • 1
  • 1
  • 7

2 Answers2

3

You can have a Map based on some unique attribute. Lets say you have date in this case.

Que
  • 126
  • 4
0

You can use a switch case for each day within the for loop to populate the day cells in one iteration

for(Reservation item: reallyBigList){
       if(item.getDate.equals(date)){
          //convert day from date to integer
          switch(day){
            case 1:
            case 2:
            case 3:
            //..
            default:
          }
          //may need multiple switch statements for month and year as reqd
        }
 }

see here for switch with nested statements.

Hope this would finish the job in one but slightly longer iteration.

Community
  • 1
  • 1
SKR
  • 21
  • 4