İsmail Çakmak
İsmail Çakmak

Reputation: 1

xamarin ListView den id alma olayı

After long efforts, I managed to pull data from the api; When I compile and click on ListVeiw1 screen, I can't get ip or name, What is the solution? Thanks.

<ListView SelectionMode="Single" ItemSelected="ListView1_ItemSelected" x:Name="ListView1".....

private async void Button_Clicked(object sender, EventArgs e)
        {
            List<TodoItem> itemsNew = new List<TodoItem>();
            using (var ic = new HttpClient())
            {
                using (var response = await ic.GetAsync("http://adress.com/api/items"))
                {
                    var content = await response.Content.ReadAsStringAsync();
                    itemsNew = JsonConvert.DeserializeObject<List<TodoItem>>(content);                 
                    ListView1.ItemsSource = itemsNew;
                }
            }
        }


  private void ListView1_ItemSelected(object sender, SelectedItemChangedEventArgs e)
  {
     string myname = e.SelectedItem.ToString();
  }

Upvotes: -1

Views: 30

Answers (1)

Jason
Jason

Reputation: 89169

you need to cast the SelectedItem to the correct type before you can access its properties

private void ListView1_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
   var item = (TodoItem)e.SelectedItem;
   // now you can access any properties of item
}

Upvotes: -1

Related Questions