title: android - list adapter problems
body: <p>I have a listview which has a textview and a checkbox in a row.</p>
  
  <p>when I select a list item, the checkbox in that row is selected, in addition also an extra checkbox of different row is selected. any idea why is this happening?</p>
  
  <p>my adapter where i am populating the listview:</p>
  
  <pre><code>public class  ContactAdaper extends BaseAdapter
  {
      private Context myContext;
      private LayoutInflater inflater;      
      private ArrayList listname;
      private ArrayList list_no;
      private List&lt;ContactPojo&gt; contactList;
      private ContactPojo contactObj;
      public ContactAdaper(ContactActivity contactActivity,ArrayList listname,ArrayList list_no,List&lt;ContactPojo&gt; listToAddContacts)
      {
          this.myContext = contactActivity;
          this.listname = listname;
          this.list_no = list_no;
          this.contactList = listToAddContacts;
      }
  
      @Override
      public int getCount() 
      {
          return listname.size();
      }
  
      @Override
      public Object getItem(int arg0)
      {
          return arg0;
      }
  
      @Override
      public long getItemId(int arg0) 
      {
          return arg0;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) 
      {
          if (convertView == null)
          {
  
              inflater = (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
              convertView = inflater.inflate(R.layout.contact_row, null);
              final ViewHolder viewHolder = new ViewHolder();
              viewHolder.txtMobNum = (TextView) convertView.findViewById(R.id.name);
              viewHolder.checkBox = (CheckBox) convertView.findViewById(R.id.checkBox);   
              viewHolder.txtName = (TextView)convertView.findViewById(R.id.id);
  
              convertView.setTag(viewHolder);
          }
  
          final ViewHolder holder = (ViewHolder) convertView.getTag();
          holder.txtMobNum.setText(list_no.get(position).toString());
          holder.txtName.setText(listname.get(position).toString());
  
  
          if(holder != null)
          {
              /*holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() 
              {
  
                  public void onCheckedChanged(final CompoundButton buttonView, boolean isChecked) 
                  {
                      //  Toast.makeText(myContext, "Selected item is :-"  +buttonView.getId(), Toast.LENGTH_LONG).show();
  
                      if(isChecked)
                      {
                          Toast.makeText(myContext, "Selected Name AND Number is :-"  +
                                  holder.txtName.getText().toString()+", "+holder.txtMobNum.getText().toString(), Toast.LENGTH_LONG).show();
  
                          contactObj = new ContactPojo();
                          contactObj.name = holder.txtName.getText().toString();
                          contactObj.mobile = holder.txtMobNum.getText().toString();
  
                          contactList.add(contactObj);
                      }
                      else
                      {
                          removeContact(holder.txtMobNum.getText().toString());
                          notifyDataSetChanged();
                          Log.d("Cont", holder.txtName.getText().toString()+" = "+holder.txtMobNum.getText().toString()+" is removed from the list ");
  
                      }
                  }
              });*/
  
              holder.checkBox.setOnClickListener(new View.OnClickListener() 
              {
  
                  @Override
                  public void onClick(View v) 
                  {
                       boolean checked = ((CheckBox) v).isChecked();
                       switch(v.getId())
                       {
                          case R.id.checkBox:
                              if (checked)
                              {
                                  Toast.makeText(myContext, "Selected Name AND Number is :-"  +
                                          holder.txtName.getText().toString()+", "+holder.txtMobNum.getText().toString(), Toast.LENGTH_LONG).show();
  
                                  contactObj = new ContactPojo();
                                  contactObj.name = holder.txtName.getText().toString();
                                  contactObj.mobile = holder.txtMobNum.getText().toString();
  
                                  contactList.add(contactObj);
                              }
                              else
                              {
                                  removeContact(holder.txtMobNum.getText().toString());
                                  notifyDataSetChanged();
                                  Log.d("Cont", holder.txtName.getText().toString()+" = "+holder.txtMobNum.getText().toString()+" is removed from the list ");
                              }
  
                              break;
                       }
                  }
              });
          }
          return convertView;              
      }      
  
      private void removeContact(String mobile)
      {
          Iterator&lt;ContactPojo&gt; it = contactList.iterator();
          while (it.hasNext())
          {
              ContactPojo contact = it.next();
              if(contact.mobile.equals(mobile)) 
              {
                  it.remove();
              }
          }
      }
  }    
  class ViewHolder 
  {
      TextView txtMobNum;
      TextView txtName;
      CheckBox checkBox;
  } 
  </code></pre>
  
  <p>//Here is my list row</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      android:layout_margin="30dp"
      &gt;
  
   &lt;TextView 
       android:id="@+id/name"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textColor="#000000"
       android:layout_marginLeft="20dp"
       /&gt;
   &lt;TextView 
       android:id="@+id/id"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginLeft="20dp"
       android:textColor="#000000"
       /&gt;
   &lt;CheckBox 
       android:id="@+id/checkBox"
       android:tag="tagCheck"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginLeft="20dp"
       android:checked="false"
       /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>