title: CheckBox in ListView multiple select
body: <p>Good day to all.</p>
  
  <p>I have a list view with checkboxes near each textview.  When I check one checkbox and scroll down, random other checkboxes also get checked.  I've read this <a href="https://stackoverflow.com/questions/5444355/android-listview-with-checkbox-problem">post</a> and a couple others here and they all say that the state of each checkbox needs to be saved in a boolean list at  <code>getView()</code>.  How would I go about doing that? </p>
  
  <p>Thanks.</p>
  
  <p><strong>Edited for code:</strong></p>
  
  <p>This is the code of the adapter, containing also the <code>getView()</code> method.</p>
  
  <pre><code>public class MyCustomAdapter extends BaseAdapter
  {
      public ArrayList&lt;Error&gt; list;
      private Context mContext;
      private LayoutInflater mInflator;
  
      public MyCustomAdapter(Context context, int textViewResourceId, ArrayList&lt;Error&gt; list)
      {
          this.list = list;
          this.mContext = context;
          mInflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      }
  
  @Override
  public int getCount() 
  {
      return list.size();
  }
  
  @Override
  public Error getItem(int position) 
  {
      return list.get(position);
  }
  
  @Override
  public long getItemId(int position) 
  {
      return 0;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) 
  {
      ViewHolder holder;
  
      if(convertView == null)
      {
          holder = new ViewHolder();
  
          convertView = mInflator.inflate(R.layout.listviewrow, null);
  
          holder.text = (TextView)convertView.findViewById(R.id.text);
          holder.checkbox = (CheckBox)convertView.findViewById(R.id.checkbox);
  
          convertView.setTag(holder);
      }
      else
      {
          holder = (ViewHolder)convertView.getTag();
      }
  
      final int pos = position;
      holder.text.setText(list.get(position).getDescription());
      holder.checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() 
      {
  
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 
          {
              list.get(pos).setChecked(isChecked);
          }
      });
  
      return convertView;
  }
  
  static class ViewHolder
  {
      TextView text;
      CheckBox checkbox;
  }
  
  
  
  }
  </code></pre>