I have an activity which extends ListActivity. It has many things but amongst them it shows the articles the user has purchased with an adapter. Well I have a method that the user can delete the items from the list. The problem is when there is only one item. If I try to delete the last one the app crashes. Here is a it of my code:

```
public class Ventas extends ListActivity {

```

......

```
lv = getListView();

```

......

```
 protected void confirmRemoval(final int arg2) {
    // TODO Auto-generated method stub
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle(getResources().getString(R.string.ventas));
    alertDialog.setMessage(getResources().getString(R.string.confirmacion2));
    alertDialog.setButton("Si",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    if(adapter2.mEvents.size()>=1){
                    adapter2.mEvents.remove(arg2);
                    } else {

                        //doesn't work
                        /*adapter2=null;
                        adapter2.notifyDataSetInvalidated();
                        lv.setVisibility(View.GONE);*/
                    }

                }
            });
    alertDialog.setButton2("No", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            dialog.dismiss();
        }
    });

    alertDialog.show();

}

```

here is the adapter and wrapper:

```
private class EventAdapter2 extends BaseAdapter {

    public ArrayList<Articulo> mEvents = null;

    public EventAdapter2(Context c, ArrayList<Articulo> clientes) {
        mContext = c;
        mEvents = clientes;
    }

    public int getCount() {
        return mEvents.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        EventEntryView2 btv;
        if (convertView == null) {
            btv = new EventEntryView2(mContext, mEvents.get(position));

        } else {
            btv = (EventEntryView2) convertView;
            String title1 = mEvents.get(position).getCantidad() + "";

            if (title1 != null) {
                btv.setText1Title(title1);
            }

            String title2 = mEvents.get(position).getDescripcion();

            if (title2 != null) {
                btv.setText2Title(title2);
            }

            String title3 = mEvents.get(position).getpVenta() + "0";

            if (title3 != null) {
                btv.setText3Title(title3);
            }

            String title4 = (mEvents.get(position).getCantidad() * mEvents
                    .get(position).getpVenta()) + "0";

            if (title4 != null) {
                btv.setText4Title(title4);
            }

        }

        return btv;

    }

    private Context mContext;

}

private class EventEntryView2 extends LinearLayout {

    private TextView text1;
    private TextView text2;
    private TextView text3;
    private TextView text4;
    private View inflatedView;

    public EventEntryView2(Context context, Articulo resp) {
        super(context);
        this.setOrientation(VERTICAL);

        inflatedView = View.inflate(context, R.layout.results, null);
        text1 = (TextView) inflatedView.findViewById(R.id.textView1);
        text2 = (TextView) inflatedView.findViewById(R.id.textView2);
        text3 = (TextView) inflatedView.findViewById(R.id.textView3);
        text4 = (TextView) inflatedView.findViewById(R.id.textView4);

        String t = resp.getCantidad() + "";
        text1.setText(t);

        String t1 = resp.getDescripcion();
        text2.setText(t1);

        String t2 = resp.getpVenta() + "0";
        text3.setText(t2);

        String t3 = (resp.getCantidad() * resp.getpVenta()) + "0";
        text4.setText(t3);

        addView(inflatedView, new LinearLayout.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    }

    public void setText4Title(String title4) {
        text4.setText(title4);
    }

    public void setText3Title(String title3) {
        text3.setText(title3);
    }

    public void setText2Title(String title2) {
        text2.setText(title2);
    }

    public void setText1Title(String title1) {
        text1.setText(title1);

    }
}

```

as you can see when I have only one item left I have tried to set adapter to null or adapter.notifyDataSetInvaliadted or even making the listview invisible, nothing works. What happens is when I click ok nothing changes then when I click a second time it all crashes

What I would like is the listView to disappear when the adapter is empty but I am now out of ideas, is it even possible?
Any ideas?

**EDIT: 
Thank you all for the answers but the problem was I was modifying the list from inside an inner anonymous class. It is actually pretty simple, create a method and call it from inside the dialog, once the array is empty the list disappears automatically:**

```
 protected void removeFromList(int arg2) {  
    adapter2.mEvents.remove(arg2);
    adapter2.notifyDataSetChanged();
  }

```