[英]xamarin ListView den id alma olayı
After long efforts, I managed to pull data from the api;经过长时间的努力,我设法从api中提取了数据; When I compile and click on ListVeiw1 screen, I can't get ip or name, What is the solution?
当我编译并点击ListVeiw1屏幕时,我无法获取ip或name,如何解决? 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();
}
you need to cast the SelectedItem
to the correct type before you can access its properties您需要将投
SelectedItem
到正确的类型,然后才能访问它的属性
private void ListView1_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var item = (TodoItem)e.SelectedItem;
// now you can access any properties of item
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.