title: custom listview with checkbox error in android
body: <p>hi i am creating a custom listview with two chekboxes and problen is when i check a checkbox and scroll down another checkbox adjacent to the checked one also get checked i want to know why it is happening what should i do to avoid that error this is my code </p>
  
  <pre><code>public class ListTestActivity extends ListActivity {
  /** Called when the activity is first created. */
  String tag = "Events";
  String[] presidents;
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
   // Create an array of Strings, that will be put to our ListActivity
      presidents =getResources().getStringArray(R.array.pres_array);
  
          ArrayAdapter&lt;Model&gt; adapter = new InteractiveArrayAdapter(this,
                  getModel());
          Log.d(tag," event");
          setListAdapter(adapter);
          Log.d(tag," 1");
      }
  
      private List&lt;Model&gt; getModel() {
          Log.d(tag,"bht");
          int index = presidents.length;
          int positio;
          String Linux;
          //List&lt;Model&gt; list = new ArrayList&lt;Model&gt;();
          /*for(positio=0;positio&lt;=index ;++positio){
              String Linux="hai";
              List&lt;Model&gt; list = new ArrayList&lt;Model&gt;();
              list.add(get(presidents[positio]));
              list.add(get(Linux));
              Log.d(tag," 2");
                       //if(positio&gt;=10){
              return list;
  
              //}
          }*/
          List&lt;Model&gt; list = new ArrayList&lt;Model&gt;();
          //int position=0;
          //List&lt;Model&gt; list = new ArrayList&lt;Model&gt;();
          //list.add(get(presidents[position]));
          for(positio=0;positio&lt;index ;positio++){
              Linux=presidents[positio];
              list.add(get(Linux));
          }
  
          Log.d(tag,"bht1");
          /*list.add(get("Windows7"));
          list.add(get("Suse"));
          list.add(get("Eclipse"));
          list.add(get("Ubuntu"));
          list.add(get("Solaris"));
          list.add(get("Android"));
          list.add(get("iPhone"));*/
          // Initially select one of the items
          //list.get(1).setSelected(true);
          //String re=list.get(1);
          Log.d(tag," event1");
          return list;
  
      }private Model get(String s) {
          Log.d(tag," event2");
          return new Model(s);
  }}
  
  
  public class InteractiveArrayAdapter extends ArrayAdapter&lt;Model&gt; {
  String tag = "Events";
  private final List&lt;Model&gt; list;
  private final Activity context;
  
  public InteractiveArrayAdapter(Activity context, List&lt;Model&gt; list) {
      super(context, R.layout.rowbuttonlayout, list);
      this.context = context;
      this.list = list;
  }
  
  static class ViewHolder {
      protected TextView text;
      protected CheckBox checkbox,checkbox1;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      Log.d(tag," 3");
      View view = null;
      if (convertView == null) {
          LayoutInflater inflator = context.getLayoutInflater();
          view = inflator.inflate(R.layout.rowbuttonlayout, null);
          final ViewHolder viewHolder = new ViewHolder();
          viewHolder.text = (TextView) view.findViewById(R.id.label);
          viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check);
          viewHolder.checkbox1 = (CheckBox) view.findViewById(R.id.checkbox1);
          viewHolder.checkbox
                  .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  
                      @Override
  public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
  
  Model element = (Model)viewHolder.checkbox.getTag();
      String posit=element.getName();
  Log.d(posit,"identifyme");
  element.setSelected(buttonView.isChecked());
                          int dam=viewHolder.checkbox.getId();
                          //Log.d(dam,"bbb");
                          System.out.println("Checked : " + viewHolder.checkbox.getId());
  
                      }
                  });
          viewHolder.checkbox1
          .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  
              @Override
  public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
  
  Model element = (Model) viewHolder.checkbox1.getTag();
  
      String posit=element.getName();
  
                  Log.d(posit,"identify");
                  element.setSelected(buttonView.isChecked());
  
  
  
                  //Log.d(tag,"identifyme");
              }
          });
  
          view.setTag(viewHolder);
          Log.d(tag,"me");
          viewHolder.checkbox.setTag(list.get(position));
          viewHolder.checkbox1.setTag(list.get(position));
      } else {
          view = convertView;
          Log.d(tag,"meeee");
          ((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
          ((ViewHolder) view.getTag()).checkbox1.setTag(list.get(position));
      }
      ViewHolder holder = (ViewHolder) view.getTag();
      holder.text.setText(list.get(position).getName());
      //String Dis=list.get(position).getName();
      //Log.d(Dis," event7");
      holder.checkbox.setChecked(list.get(position).isSelected());
      holder.checkbox1.setChecked(list.get(position).isSelected());
      Log.d(tag," event7");
  
      return view;
  
  }
  }
  
  public class Model {
  String tag = "Events";
  private String name;
  private boolean selected;
  
  public Model(String name) {
      this.name = name;
      selected = false;
      Log.d(tag," ev");
  }
  
  public String getName() {
      Log.d(tag," eve");
      return name;
  }
  
  public void setName(String name) {
      Log.d(tag," nt");
      this.name = name;
  }
  
  public boolean isSelected() {
      Log.d(tag," t");
      return selected;
  }
  
  public void setSelected(boolean selected) {
      Log.d(tag," eventer");
      this.selected = selected;
  }
  
  }
  </code></pre>