Bug 45689

Summary: ListView.SetupContent called as many times as the number of items
Product: Forms Reporter: Andrei.N <nitescua>
Component: AndroidAssignee: Bugzilla <bugzilla>
Status: CONFIRMED ---    
Severity: normal CC: Anthony.Coqui, david, jas, nitescua, paul.dipietro
Priority: Normal    
Version: 2.3.4   
Target Milestone: ---   
Hardware: PC   
OS: Windows   
See Also: https://bugzilla.xamarin.com/show_bug.cgi?id=60033
Tags: listview ac Is this bug a regression?: ---
Last known good build:
Attachments: Test application

Description Andrei.N 2016-10-19 11:54:28 UTC
I have ListView with HasUnevenRows = true, ListViewCachingStrategy.RecycleElement and I override `SetupContent`.

 `SetupContent` is being called each time you add an item to the ListView, which makes snes, but it's called as many times as the number of items. 


 So if you have zero items: add one item, 'SetupContent` is called once.
 Now you add a new item (there are 2 items now) `SetupContent` is called twice, one time with `index` parameter with value 0, and the second time with `index` parameter = 2
 Now you add a new item (there are 3 items now) `SetupContent` is called three times (parameter `index` is 0,1 and 2 respectively)
 And so on...
Comment 1 Jason Smith [MSFT] 2016-10-19 18:00:18 UTC
can you please attach a reproduction case?
Comment 2 Andrei.N 2016-10-19 19:12:59 UTC
Created attachment 18128 [details]
Test application

The issue is with the 'ListViewCachingStrategy.RecycleElement'.
Comment 3 Andrei.N 2016-10-19 19:22:01 UTC
More info:

The issue is only with the 'ListViewCachingStrategy.RecycleElement'. 
Without it set, SetupContent is called once when item is added.

The test application was created in VS2015 and uses latest but the issue is the same with the current released version

Look to the MainPage.xaml.cs, it's the only place where code is.

Another thing I noticed: 
When tapping on an item or keeping the item pressed, `SetupContent` is repeatedly called, this time for just the tapped/pressed item, but I wonder if this right. Shouldn't `SetupContent` always be called only once for an item when its cell is created?
Comment 4 Andrei.N 2016-10-19 19:24:39 UTC
If the override of `SetupContent` gets called so many times, I assume so is the base.
Comment 5 Andrei.N 2016-10-19 20:22:51 UTC
I forgot to mention that I see the issue on Android. I haven't tested it on iOS.
Comment 6 Paul DiPietro [MSFT] 2017-03-24 20:38:35 UTC
iOS appears to only make one call to SetupContent. Checked against the latest