Example #1
0
    LoopListViewItem2 InitScrollView(LoopListView2 listView, int index)
    {
        if (index < 0 || index >= TotalItemCount)
        {
            return(null);
        }

        UserData itemData = GetItemDataByIndex(index);

        if (itemData == null)
        {
            return(null);
        }
        //get a new item. Every item can use a different prefab, the parameter of the NewListViewItem is the prefab’name.
        //And all the prefabs should be listed in ItemPrefabList in LoopListView2 Inspector Setting
        LoopListViewItem2 item       = listView.NewListViewItem("UserItem");
        UserItem          itemScript = item.GetComponent <UserItem>();

        if (item.IsInitHandlerCalled == false)
        {
            item.IsInitHandlerCalled = true;
            itemScript.Init();
        }
        if (itemScript != null)
        {
            itemScript.SetItemData(itemData, index);
        }
        return(item);
    }