title: Deleting checked ListView items
body: <p>I'm trying to delete <code>ListView</code> items that are checked. It works if there is only one item checked but if there are two or three then the app force closes. On the error log it says:</p>
  
  <blockquote>
    <p>E/AndroidRuntime(2173): java.lang.IndexOutOfBoundsException: Invalid location 2, size is 2 </p>
  </blockquote>
  
  <p>When having three items on the list and deleting 2. Can anyone help with correcting this error? Here is the code:</p>
  
  <pre><code>    public void delete() {
      btnDelete = (Button) findViewById(R.id.btnDelete);
      btnDelete.setOnClickListener(new OnClickListener() {
  
          public void onClick(View v) {
              for (int i = 0; i &lt; list.getChildCount(); i++) {
                  View view = list.getChildAt(i);
  
                   CheckedTextView cv = (CheckedTextView) view.findViewById(R.id.checkList);
                   if(cv.isChecked()){
                      Log.i("DELETE", adapter.getItem(i).toString()+"   "+cv.toString());
  
                       adapter.remove(adapter.getItem(i));
                   }
                   adapter.notifyDataSetChanged();
  
              }
             Toast.makeText(getApplicationContext(), "Selected Items Cleared", Toast.LENGTH_SHORT).show();
         }
      });
     }
  </code></pre>