Bug 45689 - ListView.SetupContent called as many times as the number of items
Summary: ListView.SetupContent called as many times as the number of items
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android (show other bugs)
Version: 2.3.4
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-10-19 11:54 UTC by Andrei.N
Modified: 2017-10-06 19:26 UTC (History)
5 users (show)

See Also:
Tags: listview ac
Is this bug a regression?: ---
Last known good build:


Attachments
Test application (188.79 KB, application/x-zip-compressed)
2016-10-19 19:12 UTC, Andrei.N
Details

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. 

 Example:

 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 2.3.3.163-pre3 but the issue is the same with the current released version 2.3.2.127.

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 2.3.5.73-nightly.

Note You need to log in before you can comment on or make changes to this bug.