How to filter a custom ListAdapter in android?
<p>I have searched a lot, but no any solutions are working for me. I am seting a custom arrayadapter which has a imageview and a textview. I kept an edittext where i want to add text and i wish to get the list filtered by these given texts, When i use a string type array adapter this works great, but its not working in my custom adapter, here is my code:</p>

<pre><code>public class CurrenciesFrom extends Activity implements OnItemClickListener {

    ListView lvCurrencies;
    String[] countryCode = { "BDT Bangladesh","BBF bafa" ,"USD America", "UMK Umaka","KRW Korea",
            "INR India" };
    int[] flag = { R.drawable.bdt, R.drawable.usd, R.drawable.aud,
            R.drawable.ic_launcher ,R.drawable.usd, R.drawable.aud};
    ArrayAdapter&lt;Currency&gt; adapter;
    List&lt;Currency&gt; l;
    EditText etsearch;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.currencies);
        initializer();
        lvCurrencies.setAdapter(adapter);
        lvCurrencies.setOnItemClickListener(this);
        etsearch.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // TODO Auto-generated method stub

            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                // TODO Auto-generated method stub

            }

            @Override
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub


                CurrenciesFrom.this.adapter.getFilter().filter(s.toString());
            }
        });
    }

    private List&lt;Currency&gt; getModel() {
        List&lt;Currency&gt; list = new ArrayList&lt;Currency&gt;();
        for (int i = 0; i &lt; countryCode.length; i++) {

            list.add(get(countryCode[i], flag[i]));
        }

        list.get(1).setSelected(true); // select one item by default
        return list;
    }

    private Currency get(String s, int place) {
        return new Currency(s, place);
    }

    private void initializer() {

        lvCurrencies = (ListView) findViewById(R.id.lvCurrencies);
        etsearch=(EditText)findViewById(R.id.etSearch);
        lvCurrencies.setTextFilterEnabled(true);
        // countryCode = getResources().getStringArray(R.array.Currencies);
        l = getModel();

        Collections.sort(l, new Comparator&lt;Currency&gt;() {
            @Override
            public int compare(Currency c1, Currency c2) {
                return c1.getName().compareToIgnoreCase(c2.getName());
            }
        });

        adapter = new Customarrayadapter(this, l);
    }
</code></pre>

<p>My custom adapter class is:</p>

<pre><code>package com.powergroupbd.yahoo;

import java.util.List;

import android.app.Activity;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

public class Customarrayadapter extends ArrayAdapter&lt;Currency&gt; {

    private final List&lt;Currency&gt; list;
    private final Activity context;

    public Customarrayadapter(Activity context, List&lt;Currency&gt; list) {
        super(context, R.layout.showlist, list);
        this.context = context;
        this.list = list;
    }

    static class ViewHolder {
        protected TextView text;
        protected ImageView sub;
        protected CheckBox checkbox;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        if (convertView == null) {
            LayoutInflater inflator = context.getLayoutInflater();
            view = inflator.inflate(R.layout.showlist, null);
            final ViewHolder viewHolder = new ViewHolder();
            viewHolder.text = (TextView) view.findViewById(R.id.label);
            viewHolder.text.setTextColor(Color.WHITE);
            viewHolder.sub = (ImageView) view.findViewById(R.id.sub);

            viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check);
            viewHolder.checkbox
                    .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                        @Override
                        public void onCheckedChanged(CompoundButton buttonView,
                                boolean isChecked) {
                            Currency element = (Currency) viewHolder.checkbox.getTag();
                            element.setSelected(buttonView.isChecked());
                            System.out.println("Checked : " + element.getName());
                        }
                    });
            view.setTag(viewHolder);
            viewHolder.checkbox.setTag(list.get(position));
        } else {
            view = convertView;
            ((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
        }
        ViewHolder holder = (ViewHolder) view.getTag();
        holder.text.setText(list.get(position).getName());
        holder.sub.setImageResource(list.get(position).getPlace());
        holder.checkbox.setChecked(list.get(position).isSelected());
        return view;
    }
}
</code></pre>

<p>Please help me :(</p>
