Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between ListView invalidate() vs invalidateViews()?

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.

like image 401
Sid Avatar asked Oct 30 '22 21:10

Sid


1 Answers

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.

like image 122
The Original Android Avatar answered Nov 15 '22 06:11

The Original Android