Recyclerview项目长按不使用搜索视图?

时间:2018-02-05 08:33:44

标签: android android-recyclerview

我有一个应用程序,包含recycleviewview和searchview on long press item在正常列表的情况下正常工作,但是当我使用searchview键入任何内容时它会出现在顶部,但当我点击该项目时,我总是得到一个来自位置0的正常列表中的项目。如何解决此问题。

代码: -

public Filter getFilter() {
    return new Filter() {
        @Override
        protected FilterResults performFiltering(CharSequence constraint) {


            String charString = constraint.toString();
            if (charString.isEmpty()) {
                mFilterList = models;
            } else {
                ArrayList<UserListingModel> filteredList = new ArrayList<>();
                for (UserListingModel userListingModel : models) {
                    if (userListingModel.getUseName().toLowerCase().contains(charString.toLowerCase()) || userListingModel.getUseName().toUpperCase().contains(charString.toUpperCase())) {
                        filteredList.add(userListingModel);
                    }
                }
                mFilterList = filteredList;
            }
            FilterResults filterResults = new FilterResults();
            filterResults.values = mFilterList;
            return filterResults;
        }

        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {
            mFilterList = (ArrayList<UserListingModel>) results.values;
            notifyDataSetChanged();
        }
    };
}

searchview代码: -

 mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            Log.e(TAG, "Position");
            Users.mAdapter.getFilter().filter(query);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            Users.mAdapter.getFilter().filter(newText);
            return false;
        }
    });

0 个答案:

没有答案