0

I am facing a problem of my filtered ListView not updating.

In my application there is a custom ListView which has a two TextView and one ImageView as a row elements.

The filter works fine but my custom ListView is not updated in publishResults().

@Override
protected FilterResults performFiltering(CharSequence constraint)
{
    FilterResults results = new FilterResults();
    if (constraint == null || constraint.length() <= 0) {
        results.count = ListAdapter.this.mStringFilterList.size();
        results.values = ListAdapter.this.mStringFilterList;
    } else {
        ArrayList<Ezomart> filterList = new ArrayList();
        for (int i = 0; i < ListAdapter.this.mStringFilterList.size(); i++) {
            if (((Ezomart) ListAdapter.this.mStringFilterList.get(i)).getTitle().toUpperCase().contains(constraint.toString().toUpperCase())) {
                Ezomart country = new Ezomart();
                country.setTitle(((Ezomart)ListAdapter.this.mStringFilterList.get(i)).getTitle());
                Log.d("SRI",mStringFilterList.get(i).getTitle());
                country.setSubCategory(((Ezomart) ListAdapter.this.mStringFilterList.get(i)).getSubCategory());
                country.setArea(((Ezomart) ListAdapter.this.mStringFilterList.get(i)).getArea());
                country.setThumbnailUrl(((Ezomart) ListAdapter.this.mStringFilterList.get(i)).getThumbnailUrl());
                country.setNumber(((Ezomart) ListAdapter.this.mStringFilterList.get(i)).getNumber());
                filterList.add(country);
            }
        }
        results.count = filterList.size();
        results.values = filterList;
    }
    return results;
}

protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
    ListAdapter.this.ezoItems = (List<Ezomart>) filterResults.values;
    if (filterResults.count > 0) {
        notifyDataSetChanged();
    } else {
        notifyDataSetInvalidated();
    }
}
jbrulmans
  • 975
  • 1
  • 11
  • 32
Srikanth86in
  • 107
  • 2
  • 12

1 Answers1

-1

I found the answer by following the link below. Thanks to MBH.

I had to add this code in my fragment.

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        // What i have added is this
        setHasOptionsMenu(true);
    }

For reference please follow the link:

Android search with Fragments

Community
  • 1
  • 1
Srikanth86in
  • 107
  • 2
  • 12
  • 1
    Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Bhargav Rao May 17 '16 at 11:35