5

What is the difference between ListView.invalidate() and ListView.invalidateViews()?

For me, invalidate() alone did not work. Whereas invalidateViews() worked just the way I wanted i.e. to redraw the List items.

Sid
  • 1,270
  • 2
  • 15
  • 30

1 Answers1

2

According to Android webpage View Invalidate , ListView.invalidate() will

Invalidate the whole view. If the view is visible, onDraw(android.graphics.Canvas) will be called

This redraws the Canvas background through onDraw event. This is useful when the looks/feel have changed.

ListView.invalidateViews(), stated on the Android AbsListView invalidateViews,

Causes all the views to be rebuilt and redrawn.

I think this means it will "rebuild" the modified data associated with the ListView, and update the looks/feel. However, this updates child views as well, and it is time consuming. Normally I use notifyDataSetChanged() of BaseAdapter when data has changed.

In conclusion, use the method that is appropriate for your needs.

The Original Android
  • 6,147
  • 3
  • 26
  • 31