Reputation: 6691
I have been using using listview since long but suddenly I experienced some of its random behaviour. When I call invalidateViews() on listviews, in some cases it re-inflates the views for each row and in some cases it doesn't. This is completely random. Can you tell me exactly how does it works? Ideally it should just refresh the data inside views(rows) and not inflate them again.
Thanks
Upvotes: 1
Views: 3958
Reputation: 4383
Calling invalidateViews() on a ListView should not re-inflates the ListView item views. The only way to force the ListView to re-inflates its item views, meaning that the recycled views are cleared, is by resetting the ListView adapter ( I had to dig in the source code to discover that ).
If you take a look at the invalidateViews() method implementation (source code in AbsListView.java), you will see this (Android API 16) :
/**
* Causes all the views to be rebuilt and redrawn.
*/
public void invalidateViews() {
mDataChanged = true;
rememberSyncState();
requestLayout();
invalidate();
}
The method rememberSyncState() implemented in AdapterView.java stores the ListView's position of the selected item (if any), you can check it out.
The requestLayout() method takes care of the measuring, laying out, and drawing (as far as I know) so nothing here too.
And finally invalidate() is used to force the list view to draw (with the new measurements, ...)
So calling invalidateViews() should not force the list view to re-inflate its views. Could you be re-setting the adapter somewhere so it re-inflates all the views ?
Upvotes: 2
Reputation: 24750
adapter's getView() method has parameter convertView which is null first time when you populate a listview, later when you scroll/invalidate your listview convertView is not null so you can use it and dont need to inflate a new row
Upvotes: 0
Reputation: 544
Actually, listview.invalidateViews()
causes all the views to be rebuilt and redrawn. You can come to know this when you look on the description gets displayed in eclipse when you try to select invalidateViews().
Upvotes: 0