title: Deleting the checked items in the listview
body: <p>I want to make an app which includes a <code>listView</code> with check boxes and a two buttons named <code>add</code> and <code>delete selected</code>. I want to delete all the item that are checked in the list view.I am unable to do that despite of my lot of efforts. Any help would be appreciated.</p>
  
  <p>Here is my code</p>
  
  <pre><code>package com.example.chkbokinlistview;
  
  public class Adapter extends ArrayAdapter&lt;Movies&gt; {
  
      ArrayList&lt;Movies&gt; data;
      Context context;
      int id;
      private Holder h;
  
      public Adapter(Context context, int textViewResourceId, ArrayList&lt;Movies&gt; objects) {
          super(context, textViewResourceId, objects);
          this.data = objects;
          this.context = context;
          this.id = textViewResourceId;
      }
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          final int p = position;
          View v = convertView;
          LayoutInflater l = ((Activity)context).getLayoutInflater();
          h = new Holder();
          if (v == null) {
              v = l.inflate(id, parent, false);
              h.tv = (TextView) v.findViewById(R.id.textView1);
              h.cb = (CheckBox) v.findViewById(R.id.checkBox1);
              v.setTag(h);
          }else{
              h = (Holder) v.getTag();
              h.cb.setChecked(true);
          }
          h.tv.setText(data.get(position).movieName);
          h.cb.setChecked(data.get(position).deleted);
          return v;
      }
      public void delete(){
          //how to delete all the items that are checked
      }
  
       class Holder{
          TextView tv;
          CheckBox cb;
      }
  
  }
  </code></pre>
  
  <p>MainActivity.java</p>
  
  <pre><code>@Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          lv = (ListView) findViewById(R.id.lv);
          bDelete = (Button) findViewById(R.id.bDelete);
          bAdd = (Button) findViewById(R.id.bAdd);
  
          list = new ArrayList&lt;Movies&gt;();
          a = new Adapter(this, R.layout.listitem, list);
          lv.setAdapter(a);
  
          bDelete.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  a.delete();
              }
          });
          bAdd.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  final EditText et = new EditText(MainActivity.this);
                  dialog = new AlertDialog.Builder(MainActivity.this)
                  .setPositiveButton("OK", new DialogInterface.OnClickListener() {
  
                      @Override
                      public void onClick(DialogInterface arg0, int arg1) {
                          // TODO Auto-generated method stub
                          list.add(new Movies(et.getText().toString(), false));
                          a.notifyDataSetChanged();
                          dialog.dismiss();
                      }
                  })
                  .setTitle("ADD Movie")
                  .setView(et)
                  .create();
                  dialog.show();
              }
          });
      }
  </code></pre>