Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Search Query in SearchBar Working in IOS But Not in Android

$
0
0

I created a sample Pet List with a Search View at the very top. The Search View would help user filter results of the List. The implementation works in IOS but I get an error in Android.

in IOS:

in Android:

Here is How I implemented it:
1. I created a view model with the SearchItem as one of the properties
public class PetsViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private IList _pets;
private IList originalList;
private int _current;
private string _searchTerm;

    public string SearchTerm {
        get => _searchTerm;
        set
        {
            if (_searchTerm != value)
            {
                _searchTerm = value;
                RaisePropertyChanged();
                if (string.IsNullOrWhiteSpace(_searchTerm))
                {// if search string is null List to original list
                    Pets = originalList;
                }
                else
                {// show data that has filtered data
                    var data = Pets.Where(i => i.Name.Contains(_searchTerm));
                    Pets = (IList<Pet>)data;
                }
            }
        }

    }
  1. in XAML I used binding with the SearchBar

    SearchBar Placeholder="Name or Keyword" Text="{Binding SearchTerm, Mode=TwoWay}"


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>