Listview过滤器无法正常工作

时间:2016-11-14 07:00:58

标签: android listview

我尝试过执行listview过滤器。但是过滤有时候不能正常工作。有时它的工作正常。我不知道这个错误是怎么发生的。我试过这个:

 public Filter getFilter() {
        if (valueFilter == null) {
            valueFilter = new ValueFilter();
        }
        return valueFilter;
    }

    private class ValueFilter extends Filter {
        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            FilterResults results = new FilterResults();
            List<HomepageGS> filterList = new ArrayList<HomepageGS>();
            if (constraint != null && constraint.length() > 0) {

                for (int i = 0; i < mStringFilterList.size(); i++) {
                    if ((mStringFilterList.get(i).getsearchjob_title().toUpperCase())
                            .contains(constraint.toString().toUpperCase())) {

                        HomepageGS contacts = new HomepageGS();


                        HomepageGS m = mStringFilterList.get(i);
                        filterList.add(m);
                    }


                }
                results.count = filterList.size();
                results.values = filterList;
            } else {
                results.count =  filterList.size();
                results.values = filterList;
            }
            return results;

        }

        @Override
        protected void publishResults(CharSequence constraint,
                                      FilterResults results) {
            mainpagelist1 = (List<HomepageGS>) results.values;

            notifyDataSetChanged();
        }

    }

[This is image not filter properly] 1

[This image filter properly] 2

0 个答案:

没有答案