title: checkbox in listview for multiple selection of contacts
body: <p>I had tried to to put checkbox in listview through layout inflator and I got success but the problem is when I select the multiple contacts there is no problem but when I deselect it &amp; when I scroll down &amp; then go back to that deselected checkbox its get automatically selected...</p>
  
  <pre><code>public class Contactlist_selfActivity extends ListActivity {
  /** Called when the activity is first created. */
  
  private ArrayList&lt;contact&gt; contact_list = null;
  private ProgressDialog mProgressDialog = null;
  private contactAdapter mContactAdapter = null;
  private Runnable mViewcontacts = null;
  private SparseBooleanArray mSelectedContacts = new SparseBooleanArray();
  private ArrayList&lt;contact&gt; items;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      contact_list = new ArrayList&lt;contact&gt;();
      this.mContactAdapter = new contactAdapter(this, R.layout.listview,
              contact_list);
      ListView lv = getListView();
      setListAdapter(this.mContactAdapter);
      lv.setItemsCanFocus(false);
      lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
      // }
      mViewcontacts = new Runnable() {
  
          @Override
          public void run() {
              // TODO Auto-generated method stub
              getContacts();
          }
      };
  
      Thread thread = new Thread(null, mViewcontacts, "ContactReadBackground");
      thread.start();
      mProgressDialog = ProgressDialog.show(Contactlist_selfActivity.this,
              "Please Wait...", "Retriving Contacts...", true);
  }
  
  @SuppressWarnings("unused")
  private void getContacts() {
      // TODO Auto-generated method stub
  
      try {
  
          String[] projection = new String[] {
                  ContactsContract.Contacts.DISPLAY_NAME,
                  ContactsContract.Contacts.HAS_PHONE_NUMBER,
                  ContactsContract.Contacts._ID };
  
          Cursor mCursor = managedQuery(
                  ContactsContract.Contacts.CONTENT_URI, projection,
                  ContactsContract.Contacts.HAS_PHONE_NUMBER + "=?",
                  new String[] { "1" },
                  ContactsContract.Contacts.DISPLAY_NAME);
  
          while (mCursor.moveToNext()) {
              contact contact = new contact();
  
              String contactId = mCursor.getString(mCursor
                      .getColumnIndex(ContactsContract.Contacts._ID));
  
              contact.setContactName(mCursor.getString(mCursor
                      .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));
              contact_list.add(contact);
          }
          mCursor.close();
  
          runOnUiThread(returnRes);
  
      } catch (Exception e) {
          // TODO: handle exception
          Log.d("getContacts", e.getMessage());
      }
  }
  
  public class contactAdapter extends ArrayAdapter&lt;contact&gt; {
      private int[] isChecked;
  
      public contactAdapter(Context context, int textViewResourceId,
              ArrayList&lt;contact&gt; items1) {
          super(context, textViewResourceId, items1);
          items = items1;
      }
  
      @Override
      public View getView(final int position, View convertView,
              ViewGroup parent) {
          // TODO Auto-generated method stub
          final int position_clicked = 0;
          // Log.i("asd", "getView :" + getItem(position));
  
          if (convertView == null) {
  
              LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              convertView = vi.inflate(R.layout.listview, parent, false);
          }
  
          contact contacts = items.get(position);
          isChecked = new int[items.size()];
  
          if (contacts != null) {
              final CheckBox nameCheckBox = (CheckBox) convertView
                      .findViewById(R.id.checkBox);
              nameCheckBox.setChecked(mSelectedContacts.get(position));
  
              for (int i = 0; i &lt; isChecked.length; i++) {
  
              }
  
              if (nameCheckBox != null) {
                  nameCheckBox.setText(contacts.getContactName());
              }
  
              nameCheckBox.setOnClickListener(new OnClickListener() {
  
                  @Override
                  public void onClick(View v) {
                      // TODO Auto-generated method stub
                      isChecked[position_clicked] = position;
                      Log.d("position", String.valueOf(position));
                  }
              });
  
          }
  
          return convertView;
      }
  }
  
  private Runnable returnRes = new Runnable() {
  
      @Override
      public void run() {
          // TODO Auto-generated method stub
          if (mProgressDialog.isShowing())
              mProgressDialog.dismiss();
          mContactAdapter.notifyDataSetChanged();
      }
  };
  }
  </code></pre>