title: Multiple selection listview android with custom adapter
body: <p>I have followed many tutorials on the web but finally I couldn't get what I want..So finally landed for better suggestions and answers here after all of my research.</p>
  
  <p>I have a listview with checkbox and I need to get all the checked items of listview.</p>
  
  <p>This is my Layout:</p>
  
  <pre><code>   &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:id="@+id/lineItem"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:orientation="horizontal" &gt;
      &lt;CheckBox android:id="@+id/chklist"
         android:layout_alignParentLeft="true"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"/&gt;
      &lt;TextView
         android:id="@+id/textView"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_weight="2"
         android:ems="10"
         android:padding="10dp"
         android:textColor="#800080"
         android:textSize="16sp"/&gt;
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I am using a custom adapter and I'm getting the checked items as shown:</p>
  
  <pre><code>holder.chk.setOnClickListener(new OnClickListener() {
                 @Override
                 public void onClick(View v) {
                  // TODO Auto-generated method stub
                     String listItemText = holder.txtName.getText()
                              .toString();
                  if (holder.chk.isChecked())
                      Toast.makeText(getApplicationContext(),
                              "Checked" + " " + listItemText,
                              Toast.LENGTH_SHORT).show();
                  else
                      Toast.makeText(getApplicationContext(),
                              "Unchecked" + " " + listItemText,
                              Toast.LENGTH_SHORT).show();
                 }
                });
  </code></pre>
  
  <p>And how do I get all the checked items from my ListView OnItemClick Listener:</p>
  
  <pre><code> lv.setOnItemClickListener(new OnItemClickListener() {
                                  @Override
                                  public void onItemClick(AdapterView&lt;?&gt; parent,
                                          View view, int position, long id) {
  
     //Here  I need to get all the checked items
  
      }
      });
  </code></pre>
  
  <p>Custom Adapter:</p>
  
  <pre><code>public class MyListAdapter extends BaseAdapter {
  
      public LayoutInflater inflater;
      public Activity context;
      ArrayList&lt;String&gt; arr_calllog_name = new ArrayList&lt;String&gt;();
      boolean[] itemChecked;
  
      public MyListAdapter(Activity context,
              ArrayList&lt;String&gt; arr_calllog_name) {
  
          super();
          this.context = context;
          this.arr_calllog_name = arr_calllog_name;
          this.inflater = (LayoutInflater) context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          itemChecked = new boolean[arr_calllog_name.size()];
      }
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return arr_calllog_name.size();
      }
  
      @Override
      public Object getItem(int position) {
          return arr_calllog_name.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          // TODO Auto-generated method stub
          return 0;
      }
  
      public class ViewHolder {
          CheckBox chk;
          ImageView editimage, delimage;
          TextView txtName;
          LinearLayout row;
      }
  
      @Override
      public View getView(final int position, View convertView,
              ViewGroup parent) {
          // TODO Auto-generated method stub
  
          final ViewHolder holder;
          if (convertView == null) {
              holder = new ViewHolder();
              convertView = inflater.inflate(R.layout.list, null);
              holder.chk = (CheckBox) convertView
                      .findViewById(R.id.chklist);
              holder.txtName = (TextView) convertView
                      .findViewById(R.id.textView);
              holder.row = (LinearLayout) convertView
                      .findViewById(R.id.lineItem);
              convertView.setTag(holder);
  
          } else
              holder = (ViewHolder) convertView.getTag();
  
          holder.txtName.setText(arr_calllog_name.get(position));
  
          holder.row.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  /*
                   * Intent i = new Intent(AddItems.this, AddItems.class);
                   * Bundle bundle = new Bundle(); // Add your data from
                   * getFactualResults method // to bundle String listItemText
                   * = holder.txtName.getText().toString();
                   * 
                   * bundle.putString("Listname", listItemText);
                   * i.putStringArrayListExtra("AddedList", MyList); // Add
                   * the bundle to the intent i.putExtras(bundle);
                   * startActivity(i);
                   */
  
              }
          });
  
          holder.chk.setOnClickListener(new OnClickListener() {
                 @Override
                 public void onClick(View v) {
                  // TODO Auto-generated method stub
                     String listItemText = holder.txtName.getText()
                              .toString();
                  if (holder.chk.isChecked())
                      Toast.makeText(getApplicationContext(),
                              "Checked" + " " + listItemText,
                              Toast.LENGTH_SHORT).show();
                  else
                      Toast.makeText(getApplicationContext(),
                              "Unchecked" + " " + listItemText,
                              Toast.LENGTH_SHORT).show();
                 }
                });
          return convertView;
  
      }
  
  }
  </code></pre>