Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Android] ItemTemplate count has exceeded the limit of 23. Please make sure to reuse DataTemplate objects #2931

Closed
leobragatti opened this issue Jun 4, 2018 · 5 comments
Labels
s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one.

Comments

@leobragatti
Copy link

Description

Trying to use ListView and this error always happens
ItemTemplate count has exceeded the limit of 23. Please make sure to reuse DataTemplate objects

Steps to Reproduce

  1. Just trying to use a ListView

Basic Information

  • IDE: VisualStudio Community Mac 7.5.2 (build 40)

  • Runtime:
    Mono 5.10.57
    Xamarin.Mac 4.4.1.178
    Xamarin.Android 8.3.3.2
    SDK Tools Version: 26.1.1
    SDK Platform Tools: 27.0.1
    SDK Build Tools: 27.0.3

  • Platform Target Frameworks: use target framework version

    • Android: API Level 15
  • Nuget Packages:
    Xamarin Forms 3.0.0.482510

  • Affected Devices:
    Samsung SM-J500M (API 23)

@samhouts
Copy link
Member

samhouts commented Jun 4, 2018

Hi @leobragatti! Android has a limitation of the number of cell types it can use in a single ListView. If you're not reusing your DataTemplates (i.e., you return a new DataTemplate for every list item), you'll run into this limitation quickly. Please make sure you're following the instructions in https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/templates/data-templates/. If you are still unable to proceed, please attach a small project that demonstrates the issue you're having. Thanks!

@samhouts samhouts added s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. labels Jun 4, 2018
@jassmith
Copy link

jassmith commented Jun 8, 2018

Please re-open if you are still having issues after following Sams advice.

@jassmith jassmith closed this as completed Jun 8, 2018
@leobragatti
Copy link
Author

Thanks for the help @samhouts . I checked my code and I was using the TemplateSelector in a wrong way.

@billvenhaus
Copy link
Contributor

@samhouts Do you know why a limit of 20 (23) was chosen in ListViewAdapter? I'm working on a rather large & complicated ListView that can return up to 35 unique DataTemplates in a DataTemplateSelector. I am a little curious. I haven't been able to find docs that the native Android ListView can't handle more types.

@samhouts
Copy link
Member

@billvenhaus I don't believe that it was a limitation from Android itself but an arbitrary number that we selected and hoped would be sufficient for even the most complex ListViews. The limitation from Android was that they required us to define the exact number of ViewTypes that will be used (it can't be dynamically computed, like iOS or UWP allows), and it allocates that number in memory. We didn't want to select an exceptionally large number and impact performance when it wasn't necessary for most cases.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one.
Projects
None yet
Development

No branches or pull requests

4 participants