title: Force Listview not to reuse views (Checkbox)
body: <p>I made a custom <code>Listview</code> (Without overriding <code>getView()</code> method) with each item in a Listview having a following Layout </p>
  
  <p><strong>contactlayout.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent" android:weightSum="1"&gt;
      &lt;CheckBox android:id="@+id/checkBox1" android:text="CheckBox" android:layout_width="134dp" android:layout_height="108dp" android:focusable="false"&gt;&lt;/CheckBox&gt;
      &lt;LinearLayout android:id="@+id/linearLayout1" android:layout_height="match_parent" android:orientation="vertical" android:layout_width="87dp" android:layout_weight="0.84" android:weightSum="1" &gt;
          &lt;TextView android:text="TextView" android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/name" android:layout_weight="0.03"&gt;&lt;/TextView&gt;
          &lt;TextView android:text="TextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/phone"&gt;&lt;/TextView&gt;
          &lt;TextView android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0.03" android:layout_width="match_parent" android:id="@+id/contactid" android:visibility="invisible"&gt;&lt;/TextView&gt;
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I am populating the <code>Listview</code> using a <code>SimpleCursorAdapter</code> in a following way...</p>
  
  <pre><code>Cursor c = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
  
          String from[] = new String[]{ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone.CONTACT_ID};
          int to[] = new int[]{R.id.name,R.id.phone,R.id.contactid};
          SimpleCursorAdapter s = new SimpleCursorAdapter(this,R.layout.contactlayout,c,from,to);
          lv.setAdapter(s);
  </code></pre>
  
  <p>On Click of a button I am reading the states of all the Checkboxes. The problem is, if I check one <code>CheckBox</code> several others down the line get automatically Checked. I know this is reusing of Views. How do I avoid it ?. I am not even overriding <code>getView()</code> method in this case, so I wonder if there is still any way to achieve what I want?</p>
  
  <p><strong>Answer</strong></p>
  
  <p>Finally I implemented what @sastraxi suggested...</p>
  
  <pre><code>@Override
      public View getView(int position, View convertView, ViewGroup parent) {
          View view = super.getView(position, convertView, parent);
  
          final CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkBox1);
          final TextView name = (TextView) view.findViewById(R.id.name);
          final TextView contactId = (TextView) view.findViewById(R.id.contactid);
          final int pos = position;
          checkBox.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
                  if(checkBox.isChecked())
                  {
                      checkList.add(String.valueOf(pos));
                      nameList.add(name.getText().toString());
                      contactList.add(contactId.getText().toString());
                      Log.i("Chk added",String.valueOf(pos));
                  }
                  else
                  {
                      checkList.remove(String.valueOf(pos));
                      nameList.remove(name.getText().toString());
                      contactList.remove(contactId.getText().toString());
                      Log.i("Un Chk removed",String.valueOf(pos));
                  }
              }
          });
  
          if(checkList.contains(String.valueOf(pos)))
          {
              checkBox.setChecked(true);
          }
          else
          {
              checkBox.setChecked(false);
          }
  
          return view;
      }
  </code></pre>