title: Android: ListView Multiple Selection
body: <p>Problem:</p>
  
  <p>When i click on the 2nd checkbox item in the listview then automatically 10th item is checked. I can not understand what's happen?</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  
  import android.app.Activity;
  import android.content.Context;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.CheckBox;
  import android.widget.CompoundButton;
  import android.widget.ImageButton;
  import android.widget.TextView;
  
  public class ItemAdapter extends ArrayAdapter&lt;MyItem&gt; {
  private int resId;
  Context context;
  private ArrayList&lt;MyItem&gt; itemList;
  
  public ItemAdapter(Context context, int textViewResourceId,
          List&lt;MyItem&gt; objects) {
      super(context, textViewResourceId, objects);
      this.context = context;
      this.resId = textViewResourceId;
      this.itemList = new ArrayList&lt;MyItem&gt;();
      this.itemList.addAll(objects);
  }
  
  private class ViewHolder {
      public boolean needInflate;
      public TextView txtItemName;
      public CheckBox chkItem;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder = null;
      MyItem cell = (MyItem) getItem(position);
      LayoutInflater mInflater = (LayoutInflater) context
              .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
      if (convertView == null) {
          convertView = mInflater.inflate(R.layout.listitem, null);
          holder = new ViewHolder();
          holder.txtItemName = (TextView) convertView
                  .findViewById(R.id.tvItemName);
          holder.chkItem = (CheckBox) convertView.findViewById(R.id.chkItem);
          holder.chkItem
                  .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  
                      @Override
                      public void onCheckedChanged(CompoundButton buttonView,
                              boolean isChecked) {
                          //Log.i("Pos", "" + position);
                          //cell.setSelected(buttonView.isChecked());
                      }
                  });
          convertView.setTag(holder);
  
      } else {
          holder = (ViewHolder) convertView.getTag();
      }
  
      holder.txtItemName.setText(cell.getName());
      return convertView;
    }
  }
  </code></pre>
  
  <p>"MyItem" is my pojo Class.</p>
  
  <p>OnCreate Code:</p>
  
  <pre><code> lvItemName = (ListView) findViewById(R.id.lvItemName);
      List&lt;MyItem&gt; myItemsList = new ArrayList&lt;MyItem&gt;();
  
      for (int i = 0; i &lt; items.length; i++) {
          MyItem item = new MyItem(items[i], false);
          myItemsList.add(item);
      }
  
      ItemAdapter adapter = new ItemAdapter(this, R.layout.listitem,
              myItemsList);
      lvItemName.setAdapter(adapter);
      lvItemName.setOnItemClickListener(this);
  </code></pre>
  
  <p>"items" is my String Array.</p>
  
  <p>Thanks in Advance.</p>