title: ListView with checkbox using multichoice in android
body: <p>here is my code, when i click button "b" a listview populates with a checkbox for each item, now i want to get items with check box checked into another activity, how do i acheive this, i came half way i'm confused how to do the remaining part</p>
  
  <p>here is my code
   XML file :
       </p>
  
  <pre><code>&lt;Button
      android:id="@+id/b"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="Pick contact" /&gt;
  
  &lt;ListView
      android:choiceMode="multipleChoice"
      android:id="@+id/lv"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>This is java code:</p>
  
  <pre><code>import java.util.ArrayList;
  import android.app.Activity;
  import android.content.ContentResolver;
  import android.database.Cursor;
  import android.os.Bundle;
  import android.provider.ContactsContract;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemClickListener;
  import android.widget.ArrayAdapter;
   import android.widget.Button;
  import android.widget.ListView;
  import android.widget.Toast;
  
  public class MainActivity extends Activity {
  Button b;
  int PICK_CONTACT;
  ArrayList&lt;String&gt; al;
  ArrayAdapter&lt;String&gt; aa;
  ListView lv;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      b = (Button) findViewById(R.id.b);
  
      lv = (ListView) findViewById(R.id.lv);
      al = new ArrayList&lt;String&gt;();
  
  
  
      b.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
  
              displaycontacts();
              System.out.println("size" + al.size());
              aa = new ArrayAdapter&lt;String&gt;(MainActivity.this,
                          android.R.layout.simple_list_item_multiple_choice, al);
              lv.setAdapter(aa);
  
  
          }
      });
  
      lv.setOnItemClickListener(new OnItemClickListener() {
  
          @Override
          public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int position ,long arg3) 
          {
  
              //here i should get the item which is checked
          }
      });
  
  }
  
  public void displaycontacts() {
      try {
          ContentResolver cr = getContentResolver();
          Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
                  null, null, null);
  
          if (cur.getCount() &gt; 0) {
              while (cur.moveToNext()) {
  
                  String name = cur
                          .getString(cur
                                  .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                  if (Integer
                          .parseInt(cur.getString(cur
                                  .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) &gt; 0) {
                      System.out.println("name : " + name);
                      al.add(name);
  
                  }
              }
  
          }
  
      } catch (Exception e) {
          System.out.println("Error:::::::::::::::::::" + e);
      }
  
  }
  }
  </code></pre>