title: Checking a checkbox in listview makes other random checkboxes checked too
body: <p>whenever i check a checkbox in my listview , other random checkboxes get checked too . It could be due to item recycling by listview.<p>
  I also tried setting <code>android:focusable="false"</code> to checkbox in my layout as suggested in some places, but still the onListItemClick() is not called for a row when its checkbox is checked.Only when I click somewhere else it gets called.<p>
  What I want is that only the user-checked checkboxes should remain checked until the user unchecks them.<p>I give below the code which is complete and could be run directly.</p>
  
  <p>Activity code- ProjActivity.java:</p>
  
  <pre><code>public class ProjActivity extends ListActivity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      PackageManager pm = getPackageManager();
      List&lt;ApplicationInfo&gt; packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
  
      final CopyOfMyCustomAdapter a = new CopyOfMyCustomAdapter(this, packages);
      getListView().setAdapter(a);
  }}
  </code></pre>
  
  <p>And finally, the custom layout file- testlayout.xml</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="horizontal" 
  
  &gt;
  
  &lt;CheckBox
      android:id="@+id/checkBox1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginLeft="20dp"
      android:text="CheckBox" 
      android:focusable="false"
      /&gt;
  
  &lt;ImageView
      android:id="@+id/imageView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/ic_launcher" 
      android:focusable="false"
      /&gt;
  </code></pre>
  
  <p></p>
  
  <p>UPDATE : My CustomAdapter after the suggestion in an answer below:</p>
  
  <pre><code>public class MyCustomAdapter extends ArrayAdapter&lt;ApplicationInfo&gt;  {
  
  private List&lt;ApplicationInfo&gt; appInfoList;
  private LayoutInflater mInflater;
  private PackageManager pm;
  ArrayList&lt;Boolean&gt; positionArray;
  private Context ctx;
  int[] visiblePosArray;
  private volatile int positionCheck; 
  
  public MyCustomAdapter(Context context, List&lt;ApplicationInfo&gt; myList) {
      super(context, NO_SELECTION);
      appInfoList = myList;
      ctx=context;
      mInflater =     (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      pm = context.getPackageManager();
  
      positionArray = new ArrayList&lt;Boolean&gt;(myList.size());
      for(int i =0;i&lt;myList.size();i++){
          positionArray.add(false);
      }
  }
  @Override
  public int getCount() {
      // TODO Auto-generated method stub
      return appInfoList.size();
  }
  
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
  
      View row = convertView;
      Holder holder = null;
  
      if(row==null){
          row = mInflater.inflate(R.layout.testlayout, null); 
          //  visiblePosArray[position%visiblePosArray.length]=position;
          holder = new Holder();
          holder.appIcon = (ImageView)row.findViewById(R.id.imageView1);
  
          holder.ckbox =(CheckBox)row.findViewById(R.id.checkBox1);
  
          row.setTag(holder);
      } else {
  
          holder = (Holder) convertView.getTag();
      }
  
      holder.ckbox.setFocusable(false);
      holder.appIcon.setImageDrawable(appInfoList.get(position).loadIcon(pm));
      holder.ckbox.setChecked(positionArray.get(position));
      holder.ckbox.setText(appInfoList.get(position).loadLabel(pm));
      holder.ckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
              if(isChecked ){
              System.out.println(position+"--- :)");
                  positionArray.add(position, true);
              }else
                  positionArray.add(position, false);
          }
      });
  
      return row;
  }
  static class Holder
  {
      ImageView appIcon;
      CheckBox ckbox;
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>When I scroll up and down I could see random indices changed to true in my boolean Arraylist when in syso them.</p>