Xamarin表单:提高文本搜索性能

时间:2018-02-13 03:36:58

标签: listview xamarin search

使用搜索栏和列表视图进行文本搜索时,如何提高性能?

public ICommand OnTextChangedCommand 
    {
        get 
        {
            return new Command((obj) => 
            { 
                if (obj is TextChangedEventArgs)
                {
                    var arg = obj as TextChangedEventArgs;

                    var matchedChildren = new ObservableCollection<SignInOutViewModel>(cachedCopy.Where(x => x.DisplayName.Contains(arg.NewTextValue) || x.DisplayName.Contains(arg.NewTextValue)).ToList());
                    Collection = matchedChildren;

                    if (String.IsNullOrEmpty(arg.NewTextValue))
                        Collection = new ObservableCollection<SignInOutViewModel>(cachedCopy);
                    else
                    {
                        var words = arg.NewTextValue.ToLower().Split(' ');
                        Collection = new ObservableCollection<SignInOutViewModel> (cachedCopy.Where(x =>
                        {
                            var isContain = false;
                            foreach (var word in words)
                            {
                                isContain = x.DisplayName.ToLower().Contains(word);
                            }
                            return isContain;
                        }).ToList());
                    }
                }
            });
        }
    }

我在搜索完每个字符后替换了整个列表。我知道当列表对搜索很重要时会出现性能问题。还有另一种方法吗?

0 个答案:

没有答案