title: Checkbox unchecked automatically while scrolling listview
body: <p>I have a listview with checkbox  and textbox .When I check the checkbox and scroll it up and down then it is automatically uncheck.
  How to solve this problem in listview? please give me solution.<br>
  below i put my screen shot and code.</p>
  
  <p><a href="http://i.stack.imgur.com/c1ZGB.png" rel="nofollow">screen shot</a></p>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;ListView
          android:id="@+id/lvMain"
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="1" /&gt;
  
          &lt;Button
              android:id="@+id/btnSelectAll"
              android:layout_height="wrap_content"
              android:layout_width="match_parent"
              android:text="Select All" &gt;
          &lt;/Button&gt;
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>list_item.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="horizontal" &gt;
  
      &lt;CheckBox
          android:id="@+id/cbItem"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:buttonTint="#000000"&gt;
      &lt;/CheckBox&gt;
  
      &lt;TextView
          android:id="@+id/tvItem"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textColor="#000000"&gt;
      &lt;/TextView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>package com.example.checkallcheckbox;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.ListView;
  
  public class MainActivity extends Activity {
      ListView lvMain;
      String[] name = { "Jenis", "Pratik", "Jaydeep", "Hiren", "Himansu",
              "yagnik", "Atul", "Prakas", "Nihal", "Darshan", "Chetan", "Sagar",
              "Nikhil", "Sanket", "Rahul", "Jigar" };
  
      Button btnSelectAll;
      boolean isSelectAll = true;
      ListAdapter adapter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          lvMain = (ListView) findViewById(R.id.lvMain);
          btnSelectAll = (Button) findViewById(R.id.btnSelectAll);
  
          btnSelectAll.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
                  if(isSelectAll)
                  {
                  adapter = new ListAdapter(getApplicationContext(), name, true);
                  lvMain.setAdapter(adapter);
                  adapter.notifyDataSetChanged();
                  btnSelectAll.setText("ClearAll");
                  isSelectAll=false;
                  }
                  else
                  {
                      adapter = new ListAdapter(getApplicationContext(), name, false);
                      lvMain.setAdapter(adapter);
                      adapter.notifyDataSetChanged();
                      btnSelectAll.setText("CheckAll");
                      isSelectAll=true;
  
                  }
  
              }
          });
  
          adapter = new ListAdapter(getApplicationContext(), name,false);
          lvMain.setAdapter(adapter);
          adapter.notifyDataSetChanged();
  
      }
  }
  </code></pre>
  
  <p><strong>ListAdapter.java</strong></p>
  
  <pre><code>package com.example.checkallcheckbox;
  
  import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.CheckBox;
  import android.widget.TextView;
  
  public class ListAdapter extends BaseAdapter {
  
      Context mContext;
      String[] name;
      private static LayoutInflater inflater = null;
      Boolean state=false;
  
      public ListAdapter(Context c, String[] name, boolean isSelectAll) {
          // TODO Auto-generated constructor stub
          mContext = c;
          this.name = name;
          inflater = (LayoutInflater) mContext
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          state=isSelectAll;
      }
  
      @Override
      public int getCount() {
  
          return name.length;
      }
  
      @Override
      public Object getItem(int position) {
          // TODO Auto-generated method stub
          return position;
      }
  
      @Override
      public long getItemId(int position) {
          // TODO Auto-generated method stub
          return position;
      }
  
      public class ViewHolder {
          TextView tvName;
          CheckBox cbName;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup arg2) {
          // TODO Auto-generated method stub
          ViewHolder viewHolder;
  
          if (convertView == null) {
  
              convertView = inflater.inflate(R.layout.list_item, null);
              viewHolder = new ViewHolder();
              viewHolder.tvName = (TextView) convertView
                      .findViewById(R.id.tvItem);
              viewHolder.cbName = (CheckBox) convertView
                      .findViewById(R.id.cbItem);
              convertView.setTag(viewHolder);
          } else {
              viewHolder = (ViewHolder) convertView.getTag();
          }
  
          viewHolder.tvName.setText(name[position]);
  
          if(state){
              viewHolder.cbName.setChecked(true);
          }else{
              viewHolder.cbName.setChecked(false);
          }
  
          return convertView;
      }
  
  }
  </code></pre>