Reputation: 214
So I am currently attempting to make an autocomplete feature for my Xamarin forms app. 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:
Made the "Location" entry take an input and convert it into a Google Autocomplete API URL.
Send the request to Google's Autocomplete API, turning the request into a JSON package
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:
<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.
Upvotes: 2
Views: 158
Reputation: 89082
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]
then you only want results[0].predictions
to be used as your ItemsSource
ListViewUI.ItemsSource = results[0].predictions;
and your binding would just be to the description
property
<Label Text="{Binding description}" TextColor="Black"/>
Upvotes: 3