Android : Filterable not working on text clear
<p>I have custom listview and I have implemented SearchView to filter data. When we type something for search listview get filter correctly, but when I clear some characters from search text listview doesn't filter data. It remain constant at last search position.</p>

<p>Let me explain with screenshots.</p>

<p>Here, List is not yet filtered. all item are present.
I am searching in two fields of each item(name and description).</p>

<p><a href="https://i.stack.imgur.com/ntG6e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ntG6e.png" alt="enter image description here"></a></p>

<p>In this screen I have searched from <code>cam</code> it shows me correct result.</p>

<p><a href="https://i.stack.imgur.com/asvlp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/asvlp.png" alt="enter image description here"></a></p>

<p>I have clear text till c and I am expecting resut should be two item i.e. camera and LED TV.</p>

<p><a href="https://i.stack.imgur.com/kfU9s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kfU9s.png" alt="enter image description here"></a></p>

<p>Here is my code.</p>

<blockquote>
  <p>RateListAdapter.java</p>
</blockquote>

<pre><code>public class RateListAdapter extends BaseAdapter implements Filterable {

Context context;
private SparseBooleanArray mSelectedItemsIds;
public ArrayList&lt;RateList&gt; itemRateList;
public LayoutInflater inflater = null;
public ArrayList&lt;RateList&gt; tempList;
CustomFilter filter;

public RateListAdapter(Context context, ArrayList&lt;RateList&gt; itemRateList) {
    this.context = context;
    this.itemRateList = itemRateList;
    mSelectedItemsIds = new SparseBooleanArray();
    this.tempList = itemRateList;
}

@Override
public int getCount() {
    return itemRateList.size();
}

@Override
public RateList getItem(int i) {
    return itemRateList.get(i);
}

@Override
public long getItemId(int i) {
    return i;
}

class Holder {
    TextView tv_name, tv_description, tv_amount;
    ImageView iv_itemImage;
}

@Override
public View getView(int i, View convertView, ViewGroup viewGroup) {

    Holder h = new Holder();
    RateList rateList = itemRateList.get(i);
    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    if (convertView == null) {
        convertView = inflater.inflate(R.layout.rate_list_item, viewGroup, false);
    }

    h.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
    h.tv_description = (TextView) convertView.findViewById(R.id.tv_description);
    h.tv_amount = (TextView) convertView.findViewById(R.id.tv_amount);
    h.iv_itemImage = (ImageView) convertView.findViewById(R.id.iv_itemImage);

    h.tv_name.setText(rateList.Name);
    h.tv_description.setText(rateList.description);
    h.tv_amount.setText("₹ "+rateList.amount);
    Picasso.with(context).load(rateList.image).resize(92,92).into(h.iv_itemImage);

    return convertView;
}

public void toggleSelection(int position) {
    selectView(position, !mSelectedItemsIds.get(position));
}

public void selectView(int position, boolean value) {
    if (value)
        mSelectedItemsIds.put(position, value);
    else
        mSelectedItemsIds.delete(position);
    notifyDataSetChanged();
}

public SparseBooleanArray getSelectedIds() {
    return mSelectedItemsIds;
}

public void removeSelection() {
    mSelectedItemsIds = new SparseBooleanArray();
    notifyDataSetChanged();
}

@Override
public Filter getFilter() {
    if(filter == null)
    {
        filter=new CustomFilter();
    }
    return filter;
}

private class CustomFilter extends Filter {
    @Override
    protected FilterResults performFiltering(CharSequence constraint) {

        FilterResults results=new FilterResults();

        if(constraint != null &amp;&amp; constraint.length()&gt;0) {

            constraint=constraint.toString().toLowerCase();

            ArrayList&lt;RateList&gt; filters=new ArrayList&lt;RateList&gt;();

            for(int i=0;i&lt;itemRateList.size();i++) {

                if (itemRateList.get(i).Name.toLowerCase().contains(constraint) ||
                        itemRateList.get(i).description.toLowerCase().contains(constraint)) {

                    RateList r = new RateList();
                    r.Name = itemRateList.get(i).Name;
                    r.description= itemRateList.get(i).description;
                    r.id = itemRateList.get(i).id;
                    r.image = itemRateList.get(i).image;
                    r.amount = itemRateList.get(i).amount;

                    filters.add(r);
                }
            }
            results.count = filters.size();
            results.values = filters;
        } else {
            results.count=itemRateList.size();
            results.values=itemRateList;
        }
        return results;
    }

    @Override
    protected void publishResults(CharSequence charSequence, FilterResults results) {
        itemRateList=(ArrayList&lt;RateList&gt;) results.values;
        notifyDataSetChanged();
    }
}
}
</code></pre>

<p>searchview code of </p>

<blockquote>
  <p>BookingFrament.java</p>
</blockquote>

<pre><code>searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            return true;
        }

        @Override
        public boolean onQueryTextChange(String searchQuery) {
            rateListAdapter.getFilter().filter(searchQuery);
            return false;
        }
    });
</code></pre>

<p>Please help.</p>