Create two list in your adapter one the one which is coming from the previous activity
and another one which will contain filtered data

here fl is the filtered list and l is default list

Add the following method to your adapter
and call it when needed

    public void filter(String charText) {
        charText = charText.toLowerCase(Locale.getDefault());
        fl.clear();
        if (charText.length() == 0) {
            fl.addAll(l);
        }
        else
        {
            for (ModelObject wp : l)
            {
                if (wp.getCountry().toLowerCase(Locale.getDefault()).contains(charText))
                {
                    fl.add(wp);
                }
            }
        }
        notifyDataSetChanged();
    }
Advertisements