Custom listView multiselection
<p>I am developing Listview where Multiple selection is possible,now the problem is when i scroll down or up the selection of items get lost and selection made on any other item except the selected one.</p>

<p>Below is my Activity.</p>

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

    private ArrayList&lt;Contact&gt; arr = new ArrayList&lt;Contact&gt;();
    private Context context;
    private ListView list;
    private ContactArrayAdapter adapter;
    private String strName,strNumber;
    private View view;  
    public static ArrayList&lt;Boolean&gt; arrBoolean = new ArrayList&lt;Boolean&gt;();

    @Override
    public void onCreate(Bundle savedInstance) {
        super.onCreate(savedInstance);
        setContentView(R.layout.contact_picker);
        ProgressDialog pd  = new ProgressDialog(this);
        list = (ListView)findViewById(R.id.contactList);
        arr = new ArrayList&lt;Contact&gt;();
        context = ContactPickerActivity.this;
        arr =  displayContacts();
        Log.i("ContactPicker", "Completed Displaying Contact list ::: " + arr.size());
        adapter = new ContactArrayAdapter(this,arr);
        list.setAdapter(adapter);
//              list.setAdapter(new ArrayAdapter&lt;String&gt;(this,
//                      android.R.layout.simple_list_item_multiple_choice, listContent));
        list.setOnItemClickListener(ContactSelectedListener);
        Log.i("Boolaean &gt;&gt;&gt; ", arrBoolean.size() + "");


    }

    private OnItemClickListener ContactSelectedListener = new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView&lt;?&gt; parent, View arg1, int arg2,long arg3) {
            Log.i("ListViewTest","Item Click");
            SparseBooleanArray checked = list.getCheckedItemPositions();
            for (int i = 0; i &lt; arr.size(); i++) {
                Log.i("ListViewTest", arr.get(i)+ ": " + checked.get(i));
            }
        }
    };

    private ArrayList&lt;Contact&gt; displayContacts() {

        ContentResolver cr = getContentResolver();
        Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
        Contact contact;
        if (cur.getCount() &gt; 0) {
            while (cur.moveToNext()) {
                contact = new Contact();
                String id = cur.getString(cur.getColumnIndex(People._ID));
                String name = cur.getString(cur.getColumnIndex(People.DISPLAY_NAME));
                contact.setName(name);
                arr.add(contact);
            }
        }
        return arr;
    }
}
********* Adapter *****

public class ContactArrayAdapter extends BaseAdapter {

//  private final List&lt;Contact&gt; list;
    private Context context;    

    private LayoutInflater mInflater;
    private List&lt;Contact&gt; list; 

     public ContactArrayAdapter(Context context,ArrayList&lt;Contact&gt; arrPublicData) {

        this.mInflater = LayoutInflater.from(context);
        this.list = arrPublicData;
    }

    public int getCount() {
        return list.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        final ViewHolder viewHolder;
        if (view == null) {         
            view = mInflater.inflate(R.layout.multiselect_row, null);
            viewHolder = new ViewHolder();
            viewHolder.text = (TextView) view.findViewById(R.id.txtItem);
            viewHolder.checkbox = (CheckBox) view.findViewById(R.id.chkItem);

            viewHolder.checkbox
            .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                    Contact element = (Contact) viewHolder.checkbox.getTag();
                    element.setSelected(buttonView.isChecked());
                    ContactPickerActivity.arrBoolean.add(buttonView.isChecked());
                    Log.i("Boolaean 123 &gt;&gt;&gt; ", buttonView.isChecked() + "");
                }
            });
            view.setTag(viewHolder);
            viewHolder.checkbox.setTag(list.get(position));
        } else {
            viewHolder = (ViewHolder) view.getTag();
            ((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
        }
        ViewHolder holder = (ViewHolder) view.getTag();
        holder.text.setText(list.get(position).getName());
        holder.checkbox.setChecked(list.get(position).isSelected());        
        return view;
    }

    static class ViewHolder {
    protected TextView text;
    protected CheckBox checkbox;
}
</code></pre>

<p>i m not able to get Items checked....
Any Help is appericiated...Thanx in Advance</p>
