Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

C# ObservableCollection not adding items to TabbedPage's ListViews

$
0
0

I have a method returning a List to set a ListView's ItemSource. Here are the exact calls of the nested lists.

Here is the call of the TabbedPage

`public ItemsMainTabbedPage(ObservableCollection sortedItems)
{
InitializeComponent();

for (int i = 0; i < 3; i++)
{
    ItemsPagePro page = new ItemsPagePro(sortedItems, i);
    this.Children.Add(page);
}                         

}`
Here is the ItemsPagePro where is ListView is set

`public ItemsPagePro(ObservableCollection sortedItems, int switcher)
{
InitializeComponent();
switch (switcher)
{
case 0:
Title = "Home";
listView.ItemsSource = getTabbedListResults(sortedItems, (int)TabLoadMode.All);//0
break;
case 1:
Title = "Safe";
listView.ItemsSource = getTabbedListResults(sortedItems, (int)TabLoadMode.Safe);//1
break;
case 2:
Title = "Risky";
listView.ItemsSource = getTabbedListResults(sortedItems, (int)TabLoadMode.Risky);//2
break;
}
}

private ObservableCollection getTabbedListResults(ObservableCollection sortedItems, int switcher)
{
var itemsSource = sortedItems;
ObservableCollection sortedItemsMain = new ObservableCollection();
ObservableCollection items = new ObservableCollection();
try
{
bool safe = false;
if(switcher == 1)
{
safe = true;
}
for (int i = 0; i < itemsSource.Count; i++)
{
for (int j = 0; j < itemsSource[i].Count; j++)
{
if(itemsSource[i][j].multiPassedMatchesHTML != null)
{
if (!string.IsNullOrEmpty(itemsSource[i][j].multiPassedMatchesHTML.HTMLToParse))
{
itemsSource[i][j].DetailedTips = SampleDataSource.getDetailedTips(itemsSource[i][j].multiPassedMatchesHTML.multiPassedMatches, safe);
if (itemsSource[i][j].DetailedTips != null)
{
if (itemsSource[i][j].DetailedTips.totalMatches > 3)
{
bool checkResults = checkBeforeResults(itemsSource[i][j]);
if (checkResults)
{
itemsSource[i][j].Tip = SampleDataSource.getHighestResultFromMultiPassedMatches(itemsSource[i][j].DetailedTips);
itemsSource[i][j] = switchItemTip(itemsSource[i][j]);
//if (switcher != 0)
//{
items.Add(itemsSource[i][j]);
Console.WriteLine("Item added!");
//}
}
}
}
}
}
}
//if(items.ToList().Count > 0)
//{
sortedItemsMain.Add(new Titles(items.ToList()) { Intro = itemsSource[i].Intro, imagePath = itemsSource[i].imagePath, Summary = " - " });
//}
//items.Clear();
}
if(switcher == 0)
{
return itemsSource;
}
else
{
return sortedItemsMain;
}
}
catch(Exception ex)
{
DisplayAlert("Error:", ex.Message, "OK");
return null;
}
}`
It is driving me crazy. As I am finding out, this line is messing it up. itemsSource[i][j].Tip = ... When i try changing it's value(string), without any error it messes up the rest and the other listview in the other tabs are empty.

Any idea why?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>