LoopListViewItem OnGetItemByIndex(LoopListView listView, int index) { if (index < 0 || index >= HelpUIView.Instance.TotalItemCount) { return(null); } HelpInfoItem itemData = HelpUIView.Instance.GetItemDataByIndex(index); if (itemData == null) { return(null); } LoopListViewItem item = listView.NewListViewItem("InfoItem"); ListHelpItem itemScript = item.GetComponent <ListHelpItem>(); if (item.IsInitHandlerCalled == false) { item.IsInitHandlerCalled = true; itemScript.Init(); } itemScript.SetItemData(itemData, index); return(item); }
LoopListViewItem OnGetItemByIndex(LoopListView listView, int index) { if (index < 0 || index >= DataSourceMgr.Get.TotalItemCount) { return(null); } ItemData itemData = DataSourceMgr.Get.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 LoopListViewItem item = listView.NewListViewItem("Item"); ListItem itemScript = item.GetComponent <ListItem>(); if (item.IsInitHandlerCalled == false) { item.IsInitHandlerCalled = true; itemScript.Init(); } itemScript.SetItemData(itemData, index); return(item); }
protected virtual LoopListItem OnGetItemByIndex(LoopListView listView, int index) { if (index < 0 || index >= listView.ItemTotalCount) { return(null); } if (index < 0 || index >= _curDataList.Count) { return(null); } //以下判定也可以根据需求,暴露出去用以重写 W data = _curDataList[index]; string name = _getPrefab(data, index); LoopListItem item = listView.NewListViewItem(name); item.Index = index; item.gameObject.name = index.ToString(); T itemScript = _curList.Find(t => t.m_gameobj.Equals(item.gameObject)); if (itemScript == null) { itemScript = Activator.CreateInstance <T>(); //itemScript.index = index; itemScript.setObj(item.gameObject); _curList.Add(itemScript); } else { //itemScript.index = index; } if (item.IsInitHandlerCalled == false) { item.IsInitHandlerCalled = true; } itemScript.SetItemControl(item); itemScript.Refresh(data); return(item); }
/// <summary> /// 通过索引获取列表单元 /// </summary> /// <param name="_listview"></param> /// <param name="_index"></param> /// <returns></returns> LoopListViewItem OnGetItemByIndex(LoopListView _listview, int _index) { //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 LoopListViewItem tmp_Item = _listview.NewListViewItem("Element"); ListItem tmp_itemscript = tmp_Item.GetComponent <ListItem>(); if (tmp_Item.IsInitHandlerCalled == false) { tmp_Item.IsInitHandlerCalled = true; tmp_itemscript.Init(); } _index = _index % DatasourceMgr.Instance.m_Totalitemcount; if (_index < 0) { _index = DatasourceMgr.Instance.m_Totalitemcount + _index; } PageItem tmp_Itemdata = DatasourceMgr.Instance.GetItemDataByIndex(_index); tmp_itemscript.SetItemData(tmp_Itemdata, _index); return(tmp_Item); }