// Retrieving <count> models from the data source and calling OnDataRetrieved after. // In a real case scenario, you'd query your server, your database or whatever is your data source and call OnDataRetrieved after IEnumerator FetchMoreItemsFromDataSourceAndUpdate(int count) { // Simulating data retrieving delay yield return(new WaitForSeconds(.5f)); var newItems = new MyListItemModel[count]; // Retrieve your data here /* * for (int i = 0; i < count; ++i) * { * var model = new MyListItemModel() * { * title = "Random item ", * color = new Color( * UnityEngine.Random.Range(0f, 1f), * UnityEngine.Random.Range(0f, 1f), * UnityEngine.Random.Range(0f, 1f), * UnityEngine.Random.Range(0f, 1f) * ) * }; * newItems[i] = model; * } */ OnDataRetrieved(newItems); }
// This is called anytime a previously invisible item become visible, or after it's created, // or when anything that requires a refresh happens // Here you bind the data from the model to the item's views // *For the method's full description check the base implementation protected override void UpdateViewsHolder(MyListItemViewsHolder newOrRecycled) { // In this callback, "newOrRecycled.ItemIndex" is guaranteed to always reflect the // index of item that should be represented by this views holder. You'll use this index // to retrieve the model from your data set /* * MyListItemModel model = Data[newOrRecycled.ItemIndex]; * * newOrRecycled.backgroundImage.color = model.color; * newOrRecycled.titleText.text = model.title + " #" + newOrRecycled.ItemIndex; */ MyListItemModel model = Data[newOrRecycled.ItemIndex]; newOrRecycled.IDText.text = "" + model.index; newOrRecycled.NameText.text = model.name; newOrRecycled.LevelText.text = "" + model.level; if (model.id.Equals(Config.userIdentify)) { Debug.Log(model.id); newOrRecycled.NameText.color = new Color(0f, 1f, 238f / 255f, 1f); } else { newOrRecycled.NameText.color = new Color(1f, 213f / 255f, 146f / 255f, 1f); } }
public void AddItemsAt_ListUserRanks(int index, IList <InfoUserFirebase> listUserRanks) { // Commented: the below 2 lines exemplify how you can use a plain list to manage the data, instead of a DataHelper, in case you need full control //YourList.InsertRange(index, items); //InsertItems(index, items.Length); List <MyListItemModel> myListItemModels = new List <MyListItemModel>(); for (int i = 0; i < listUserRanks.Count; i++) { var model = new MyListItemModel() { index = i + 1, id = listUserRanks[i].userID, name = listUserRanks[i].name, level = listUserRanks[i].level }; myListItemModels.Add(model); Debug.Log("ID:" + listUserRanks[i].userID); } Data.InsertItems(index, myListItemModels); Data.NotifyListChangedExternally(); }