When a list is shown and scrolled around, ListAdapter.getView() either creates a new list item view, or retools an existing view passed to it (as “convertView) to display new content.
I’m wondering, if there’s a way to get all the views created by getView()? E.g. if the list item views needs to free some resource when the activity is destroyed, it would be nice to go through all list item views and tell them to release the resource.
Well, it’s not as simple as iterating through the
ListViewusingListView#getChildAt(int)– theListViewis anAbsListViewsubclass – andAbsListViewimplements theRecycleBinused to holdViews that will be reused.Before a
Viewis placed in theRecycleBinits detached from its parent (the list view) usingViewGroup#detachViewFromParent(View), thus rendering it unaccessible usinggetChildAt(int).What you should implement is the
RecyclerListenerinterface that will notify you when aViewis moved to theRecycleBin.