Android 在recyclerview领域中实现搜索过滤器

Android 在recyclerview领域中实现搜索过滤器,android,realm,Android,Realm,使用带有动画的RecyclerView+RealmRecyclerViewAdapter适配器时,如何实现搜索过滤器 @Override public boolean onQueryTextSubmit(String query) { Toaster.make(getContext(),query); return true; } @Override public boolean onQueryTextChange(String query) { query = que

使用带有动画的
RecyclerView
+
RealmRecyclerViewAdapter
适配器时,如何实现搜索过滤器

@Override
public boolean onQueryTextSubmit(String query) {
    Toaster.make(getContext(),query);
    return true;
}

@Override
public boolean onQueryTextChange(String query) {
    query = query.toLowerCase();
    if(query.length()>0 && adapter!=null){

        recyclerView.scrollToPosition(0);*/
           //this do not update the recyclerview
        realmResult = realm.where(GameListDatabase.class).equalTo("status",status).contains("name",query).findAll();

        return true;
    }


    return false;
}

你不需要可过滤的。这对我来说很好。我将方法“applyFilter”保存在Adapter下,但可以随意将其保存在任何地方。只要搜索文本中有更改,就需要调用此方法。“applyFilter”方法调用适配器上的“update”

searchText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            groupAdapter.applyFilter(s.toString());
        }

        @Override
        public void afterTextChanged(Editable s) {}
    });


 public void applyFilter(String searchString) {
        if (searchString == null || "".equals(searchString)) {
            realmResults = realm.where(Group.class).findAllSorted("groupName");
        } else {
            realmResults = realm.where(Group.class).contains("groupName", searchString.toString().trim()).findAllSorted("groupName");
        }
        updateData(realmResults);
    }

在RecyclerView上调用notifydatachange。您应该尝试实现类Filterable并重写
getFilter()
方法。这使您的过滤器实现更清晰。你可以看看这篇文章。是否使用RealmRecyclServiceAdapter与动画无关?这是一个非常好的问题。我实现了Filterable,它可以工作,但有没有办法添加淡入/淡出之类的动画?