1

I thought I understood the recycler mechanism of Listview... but it seems I didn't.

I have a ListView of 20 items, only 10 items is visible initially. Why Android calls getView() of positions like 15 or 17 (non visible rows)?

Why convertView parameter of visible rows passed to getView() are the same? I thought if convertView is not null, it refers to a row that isn't visible anymore.

After adding some logging in getView(), I couldn't explain what really happens.

pozzugno
  • 750
  • 6
  • 19
  • 1
    https://stackoverflow.com/questions/2618272/custom-listview-adapter-getview-method-being-called-multiple-times-and-in-no-co – Mike M. Apr 19 '18 at 22:29

1 Answers1

1

convertView is a View instance that was previously returned by the getView method and is not visible anymore, its purpose is TO BE converted to a NEW ITEM assigned by the new position in the method. The adapter do it to reuse views and avoid inflating new ones. If it is calling the same visible row twice it can only be at listview inflation time (it happens).

To the first question, it inflates non-visible views so it will be available to be scrolled when you reach it.

YOU MUST: re-set all values in a convertView to a new item.

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167