title: Checkbox inside ListView custom adapter
body: <p>This is my custom_list.xml</p>
  
  <pre><code>&lt;CheckBox
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/cb"
      android:layout_marginLeft="16dp"
      android:layout_gravity="center"
      android:checked="true" /&gt;
  
  &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/nameTV"
      android:layout_gravity="center"
      android:textSize="22sp"
      android:padding="16dp" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>and this is my CustomAdapter.java</p>
  
  <pre><code>private Context context;
  private ArrayList&lt;String&gt; arrayList;
  private CompoundButton.OnCheckedChangeListener onCheckedChangeListener;
  private boolean[] mItemChecked;
  
  public CustomAdapter(Context context, ArrayList&lt;String&gt; arrayList, CompoundButton.OnCheckedChangeListener onCheckedChangeListener) {
      this.context = context;
      this.arrayList = arrayList;
      this.onCheckedChangeListener = onCheckedChangeListener;
      mItemChecked = new boolean[arrayList.size()];
      for (int i=0; i&lt;arrayList.size(); i++){
          mItemChecked[i] = true;
      }
  }
  
  private static class ViewHolder {
      TextView tv;
      CheckBox cb;
  }
  
  @Override
  public int getCount() {
      return arrayList.size();
  }
  
  @Override
  public Object getItem(int position) {
      return arrayList.get(position);
  }
  
  @Override
  public long getItemId(int position) {
      return 0;
  }
  
  public boolean itemIsChecked(int position){
      return mItemChecked[position];
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      final ViewHolder holder;
      LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
      if (convertView == null) {
          convertView = inflater.inflate(R.layout.custom_list, parent, false);
          holder = new ViewHolder();
          holder.tv = (TextView) convertView.findViewById(R.id.nameTV);
          holder.cb = (CheckBox) convertView.findViewById(R.id.cb);
          convertView.setTag(holder);
      }else{
          holder = (ViewHolder) convertView.getTag();
      }
      holder.tv.setText(arrayList.get(position));
      holder.cb.setOnCheckedChangeListener(onCheckedChangeListener);
      return convertView;
  }
  </code></pre>
  
  <p>While everything works fine, there is 1 problem: the checkboxes from rows 1, 2 ,3... is bound to the checkboxes from rows 8, 9, 10... so whenever I uncheck the checkbox 1, and scrolls down to checkbox 8, he's also unchecked, and vice versa.
  I guess it is something related to the view holder which doesn't recycle the checkboxes correctly, and using for rows 1 and 8 the same checkbox. Any suggestions to overcome this problem?</p>