Using SearchBox at the top of a custom ListView
<p>I want to have a <a href="http://android-helper.blogspot.se/2011/03/android-search-in-listview-example.html" rel="nofollow">search EditText at the top of my listView</a>.</p>

<p>Then I tried to create a custom ListView with chackableTextView:</p>

<pre><code>public class CheckBoxTxt extends Activity {

    private ArrayList&lt;CheckedTxtView&gt; mStrings;
    private ArrayList&lt;CheckedTxtView&gt; array_sort = new ArrayList&lt;CheckedTxtView&gt;();
    private MultiAdapter mAdapter;
    private EditText et;
    private ListView lv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mStrings = new ArrayList&lt;CheckedTxtView&gt;();
        CheckedTxtView c;
        for(int i=0; i&lt;30; i++) {
            c = new CheckedTxtView();
            c.item = "Item " + i;
            c.check = false;
            mStrings.add(c);
        }

        this.mAdapter = new MultiAdapter(this, mStrings); 
        this.lv = (ListView) this.findViewById(R.id.list);
        this.lv.setAdapter(mAdapter);
        this.lv.setOnItemClickListener(new ItemClick());

//        lv.setItemChecked(checkedItem, true);
//        lv.setSelection(checkedItem);

         et = (EditText) findViewById(R.id.seachEdit);

         et.addTextChangedListener(new TextWatcher() {
            public void afterTextChanged(Editable s) {
                // Abstract Method of TextWatcher Interface.
            }

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                // Abstract Method of TextWatcher Interface.
            }

            public void onTextChanged(CharSequence s, int start, int before, int count) {
                int textlength = et.getText().length();
                array_sort.clear();
                for(CheckedTxtView c: mStrings){
                    if (textlength &lt;= c.item.length()) {
                        if (et.getText().toString().equalsIgnoreCase((String) c.item.subSequence(0, textlength))) {
                            array_sort.add(c);
                        }
                    }
                }
                mAdapter = new MultiAdapter(getApplicationContext(), array_sort); 
                lv.setAdapter(mAdapter);
            }
        });
    }

    class ItemClick implements OnItemClickListener {
        public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {



            CheckedTextView tv = (CheckedTextView)view.findViewById(R.id.label);
            if (tv.isChecked())
            {
                tv.setChecked(false);
                mAdapter.mItems.get(position).check = false;
            }
            else
            {
                mAdapter.mItems.get(position).check = true;
                try {
                    mAdapter.mItems.get(checkedItem).check = false;
                }
                catch(Exception e) {}
            }

            checkedItem = position;
            mAdapter.notifyDataSetChanged();

//          parent.setSelection(position);
//            ((ListView)parent).setItemChecked(position, true);

        }
    }

    private static int checkedItem = -1;

    private class MultiAdapter extends ArrayAdapter&lt;CheckedTxtView&gt; {

        private ArrayList&lt;CheckedTxtView&gt; mItems;

        public MultiAdapter(Context context, ArrayList&lt;CheckedTxtView&gt; mStrings) {
            super(context, R.layout.list2, mStrings);
            this.mItems = mStrings;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            View row;

            if (convertView == null)  {
                LayoutInflater inflater = getLayoutInflater();
                row = inflater.inflate(R.layout.list2, parent, false);
            } else
                row = convertView;

            CheckedTextView txt = (CheckedTextView) row.findViewById(R.id.label);

            CheckedTxtView c = mItems.get(position); 

            txt.setText(c.item);
            txt.setChecked(c.check);

            return row;
        }
    }

    private class CheckedTxtView {
        public String item;
        public boolean check;
    }
</code></pre>

<p>The problem is: </p>

<p>1 - I search in the list using searchBox and then click on an item -> The item becomes checked.</p>

<p>2 - Then I delete the text in the searchBox, the item which I selected becomes wrong item.</p>

<p>Can you help me or give me any sample code that uses seachBox and custom Listview with chackableTextView?</p>
