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)

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


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 45689 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

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.