After Selecting Listview App is Crashed

SinghsumitSinghsumit INMember ✭✭
edited February 2018 in Xamarin.Forms

Select Item After Adding List Item, then App is Chrashed
What can i do plz help




Code Behind
List ss;
public AddMenuPage()
{
InitializeComponent();
ss =new List() { "one", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" };
SelectionListView.ItemsSource = ss;
}

    private void Button_Clicked(object sender, EventArgs e)
    {
        ss.Add("Ten");     
        SelectionListView.ItemsSource = ss;
    }

Posts

  • JoeMankeJoeManke USMember ✭✭✭✭✭

    Put a try/catch block in the Button_Clicked method and share the exception that is causing the app to crash.

  • SinghsumitSinghsumit INMember ✭✭

    thanks #JoeManke but problem is that when i add item ,its properly add then i select any item in Listview So app crashed. i don't understand and i also use try/catch but no solve this problem.

  • SinghsumitSinghsumit INMember ✭✭

    Ohhh i forget the temp list
    ss.Add("Ten");
    List sss=new List();
    foreach (var item in ss)
    {
    sss.Add(item);
    }
    SelectionListView.ItemsSource = sss;

  • JoeMankeJoeManke USMember ✭✭✭✭✭

    Alternatively, you could use an ObservableCollection instead of a List. Then the ListView will be updated with the new item when you add it to the ItemsSource instead of having to make a whole new copy of the list.

    Also binding helps.

  • SinghsumitSinghsumit INMember ✭✭

    thanks #JoeManke .:)

Sign In or Register to comment.