0

Hello I'm new to Xamarin development. I am trying to implement the address bar feature in the application. When user starts typing the address I want to show the suggestions using Googles places API.

I have already got the background service calls to google and getting the suggestions in a LIST and trying to bind the list in the VIEW. But when binding the application is crashing and look of List is also doesn't look as expected.

View:

<Entry Placeholder="From Address" x:Name="FromAddressTxtbx" Text="{Binding AddressText}" TextChanged="Handle_TextChanged_1"/>
        <ListView ItemsSource="{Binding Addresses}" >
      <ListView.ItemTemplate>
        <DataTemplate>
             <TextCell Text="{Binding Address}"/>
             </DataTemplate>
             </ListView.ItemTemplate>
           </ListView>

Can anyone please provide me a suggestion or Direction I want this look like address bar in the UBER app.

Thank in advance

LReddy
  • 117
  • 17

1 Answers1

0

Here is a solution about using Entry and ListView to show updated list when text changed in Entry.

Xaml:

<Entry x:Name="MainEntry" TextChanged="MainEntry_TextChanged" Placeholder="Inupt Adress"/>
<ListView x:Name="NameListView" HasUnevenRows="True">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <Label Text="{Binding .}" TextColor="Navy" FontSize="40"/>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

ContentPage:First setting example data for ListView,

List<string> adressnames = new List<string>()
        {
            "Alabama", "Florida" , "Kentucky" , "Missouri", "North Carolina" ,"South Dakota" , "Wisconsin"
        };
NameListView.ItemsSource = adressnames;

enter image description here

Now when Text changed , ListView will list updated data:

private void MainEntry_TextChanged(object sender, TextChangedEventArgs e)
{
    var keyword = MainEntry.Text;
    NameListView.ItemsSource = adressnames.Where(name => name.Contains(keyword));
}

enter image description here

By the way , you also can use SearchBar to achieve it:

<SearchBar x:Name="MainSearchBar" TextChanged="MainSearchBar_TextChanged"  Placeholder="Inupt Adress"/>

With text Changed method:

private void MainSearchBar_TextChanged(object sender, TextChangedEventArgs e)
{
    var keyword = MainSearchBar.Text;
    NameListView.ItemsSource = adressnames.Where(name => name.Contains(keyword));
}

enter image description here

Junior Jiang
  • 12,430
  • 1
  • 10
  • 30