[英][Xamarin]How to bind results from list into Listview?
So I am currently attempting to make an autocomplete feature for my Xamarin forms app. 因此,我目前正在尝试为Xamarin表单应用程序提供自动填充功能。 The App will take input from Google's Autocomplete API, deserialize it, and pass it into a table, which will then hand the data off to a listvbiew... Currently I have successfully done the following:
该应用程序将从Google的Autocomplete API中获取输入,对其进行反序列化,然后将其传递到表中,然后该表将数据传递给listvbiew ...目前,我已经成功完成了以下工作:
Made the "Location" entry take an input and convert it into a Google Autocomplete API URL. 使“位置”条目接受输入并将其转换为Google自动完成API URL。
Send the request to Google's Autocomplete API, turning the request into a JSON package 将请求发送到Google的Autocomplete API,将请求转换为JSON包
here is the majority of the code responsible for the above: 这是负责上述工作的大部分代码:
protected async void GetInfo(){
if (CrossConnectivity.Current.IsConnected){
try{
HttpClient webSource = new HttpClient();
Activity_Indicator.IsRunning = true;
var content = await webSource.GetStringAsync(url);
string EditedJSON = "[" + content + "]";
var DeserializedJSON = JsonConvert.DeserializeObject<List<PlacesAPI>>(EditedJSON);
ObservableCollection < PlacesAPI > results = new ObservableCollection<PlacesAPI>(DeserializedJSON);
ListViewUI.ItemsSource = results;
}
catch(Exception ey){
Debug.WriteLine("" + ey);
}
}
}
This gives me the following list: 这给了我以下列表:
From here all that I am needing to do is know how to go about taking the "description" value found in results/[0]/predictions/([0],[1],[2])
and bind it into my listview which is set up as such: 从这里开始,我要做的就是知道如何获取在
results/[0]/predictions/([0],[1],[2])
找到的“描述”值results/[0]/predictions/([0],[1],[2])
并将其绑定到我的列表视图中设置如下:
<ListView x:Name="ListViewUI">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="{Binding ???}" TextColor="Black"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
when all is said and done, it will populate the listview with three description values from the results list. 全部说完之后,它将使用结果列表中的三个描述值填充列表视图。
I want the first row to have the description value from results/[0]/predictions/[0], the second row to have the description value from results/[0]/predictions/[1], and the third row to have the description value from results/[0]/predictions/[2]
我希望第一行具有来自结果/ [0] /预测/ [0]的描述值,第二行具有来自结果/ [0] /预测/ [1]的描述值,第三行具有结果/ [0] /预测/ [2]的描述值
then you only want results[0].predictions
to be used as your ItemsSource
那么您只希望将
results[0].predictions
用作ItemsSource
ListViewUI.ItemsSource = results[0].predictions;
and your binding would just be to the description
property 并且您的绑定将只是到
description
属性
<Label Text="{Binding description}" TextColor="Black"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.