views:

25

answers:

1

I have ArrayList of custom objects that is the data underlying an ArrayAdapter for a ListView.

Sometimes this data is modified in a batch, such as fetching a set of new items from the web. When the data is modified in a batch, should notifyDataSetChanged() be called after every add() to the ArrayList

Some over simplified code:

for(Object object : newObjects){
   list.add(object);
   adapter.notifyDataSetChanged();
}

or should it be called once after all of the items in the batch have been added?

for(Object object : newObjects){
    list.add(object);
}
adapter.notifyDataSetChanged()

Say there is a batch of 50 new objects. If 50 notifyDataSetChanged() calls are made right after another, like in the first example, will the views redraw themselves 50 times in a row (I imagine a major performance hit) or will it only perform the latest call and in a sense only redraw them once?

I'm basically wondering if I can use the first method or will it have a major performance impact?

Thanks

A: 

When you call notifyDataSetChanged(), it doesn't redraw the view immediately. It's up to the UI thread controller to know when to redraw. Although it does appear instantanious. You should try it and see if there's a performance issue. We really can't answer that for you. If it makes sense to only update the listview after all the adds, then do that.

Falmarri