Hi there,
Im here again asking for advice as the last time i did it worked out so well so hoping for more advice.
I have an app i am creating which reads json from an API, the problem is there are over 2000 items in this list which i have to create entries in my scroll view for. Now in no way do i want to create 2000 items all at once.
Is there a smart way to create items in this list as the user drags down? I just cant figure out the best way to handle this. Here i have the list in which i control how many items i want to create but i want to only create around 12 at any time and as they come out of view get rid of them, if the user scrolls back up show them again?
I do have some solutions in my mind but again i want to see other peoples ideas and see if there is a simple smart solution to this.
Thanks
public void CreateItems(AllItems items, int maxAmount)
{
ClearShopData();
if (maxAmount < 0)
{
for (int i = 0; i < items.listedItems.Count; i++)
{
GameObject newEntry = Instantiate(ItemEntryPrefab, ItemParent);
ShopItem newItem = newEntry.GetComponent<ShopItem>();
newItem.SetShopItem(items.listedItems[i]);
newItem.SetItemName();
newItem.SetItemImage();
}
return;
}
else
{
for (int i = maxAmount; i > 0; i--)
{
GameObject newEntry = Instantiate(ItemEntryPrefab, ItemParent);
ShopItem newItem = newEntry.GetComponent<ShopItem>();
newItem.SetShopItem(items.listedItems[i]);
newItem.SetItemName();
newItem.SetItemImage();
}
maxAmount += maxAmount;
}
}