Autocomplete bind differently on iOS and Android

3 posts, 0 answers
  1. Ivailo
    Ivailo avatar
    3 posts
    Member since:
    Jul 2013

    Posted 02 May Link to this post

    Hi Guys, 

    I am trying to use the Xamarin.Forms Autocomplete control but it is very strange that it works in different way on iOS 10.3 and Android 6.0

     

    Actually, 
    private void RadAutoComplete_SuggestionItemSelected(object sender, Telerik.XamarinForms.Input.AutoComplete.SuggestionItemSelectedEventArgs e)         { var dataItem =  e.DataItem;

            }

    When I select an item from the autocomplete list on Android => e.DataItem is of the object type from the List which is my ItemsSource.
    But when I select an item on iOS the e.DataItem is actually string with the value of the selected object. but not the whole object containing all other information in it ? How to fix this ?

    <telerikInput:RadAutoComplete HorizontalOptions="FillAndExpand" BackgroundColor="Transparent" ItemsSource="{Binding AreaTypes}" WidthRequest="200" TextSearchPath="AreaType" Watermark="Search here..." SuggestionItemSelected="RadAutoComplete_SuggestionItemSelected" CompletionMode="Contains">

    </telerikInput:RadAutoComplete>

  2. Ves
    Admin
    Ves avatar
    2914 posts

    Posted 05 May Link to this post

    Hi Ivailo,

    Indeed, providing a unified experience across platforms is one of the main purposes of the framework. We will include a fix in our next service release. For the time being, please use the following workaround:

    private void AutoComplete_SuggestionItemSelected(object sender, Telerik.XamarinForms.Input.AutoComplete.SuggestionItemSelectedEventArgs e)
            {
                BusinessObject businessObject = e.DataItem as BusinessObject;
                if (businessObject == null)
                {
                    RadAutoComplete autoComplete = (RadAutoComplete)sender;
                    businessObject = autoComplete.FilteredItems.Cast<BusinessObject>().Where(obj => obj.Name == (string)e.DataItem).FirstOrDefault();
                }
            }
    where BusinessObject would be your data item and Name would be the property name you use to search by.

    Best regards,
    Ves
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DAve
    DAve avatar
    2 posts
    Member since:
    May 2017

    Posted 18 May Link to this post

    thanks for information, i had same problem
Back to Top