title: IndexOutOfBoundsException when removing a listView item with delay
body: <p>I created an adapter with items that contains remove buttons. When the user click the button the item should be removed. 
  If I use this code: </p>
  
  <pre><code>list.remove(item);
  notifyDataSetChanged();
  </code></pre>
  
  <p>it succeeds. But when I added animation the application crashes with this exception:</p>
  
  <pre><code>java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
          at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
          at java.util.ArrayList.get(ArrayList.java:311)
          at android.widget.HeaderViewListAdapter.isEnabled(HeaderViewListAdapter.java:164)
          at android.widget.ListView.dispatchDrawWithBounce(ListView.java:3324)
          at android.widget.ListView.dispatchDraw(ListView.java:3073)
          at android.view.View.draw(View.java:6936)
          at android.widget.AbsListView.draw(AbsListView.java:3005)
          at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
          at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
          at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
          at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
          at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
          at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
          at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
          at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
          at android.view.View.draw(View.java:6936)
          at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
          at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:870)
          at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
          at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
          at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
          at android.view.View.draw(View.java:6936)
          at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
          at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
          at android.view.View.draw(View.java:6936)
          at android.widget.FrameLayout.draw(FrameLayout.java:357)
          at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
          at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
          at android.view.View.draw(View.java:6936)
          at android.widget.FrameLayout.draw(FrameLayout.java:357)
          at                                                                               
  com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1917)
          at android.view.ViewRoot.draw(ViewRoot.java:1530)
          at android.view.ViewRoot.performTraversals(ViewRoot.java:1266)
          at android.view.ViewRoot.handleMessage(ViewRoot.java:1868)
          at android.os.Handler.dispatchMessage(Handler.java:99)
          at android.os.Looper.loop(Looper.java:130)
          at android.app.ActivityThread.main(ActivityThread.java:3691)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:507)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
          at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Source of adapter:  </p>
  
  <pre><code>public class SearchHistoryAdapter extends BaseAdapter {
  private List&lt;SearchItem&gt; list;
  
  public SearchHistoryAdapter( List&lt;SearchItem&gt; list ){
      this.list = list;
  }
  
  @Override
  public int getCount(){
      return list.size();
  }
  
  @Override
  public Object getItem( final int i ){
      return list.get( i );
  }
  
  @Override
  public long getItemId( final int i ){
      return 0;
  }
  
  @Override
  public View getView( final int i, final View convertView, final ViewGroup parent ){
      SearchItem item = list.get( i );
      View row = convertView;
      final ContentHolder holder;
      if( convertView == null ){
          holder = new ContentHolder();
          row = LayoutInflater.from( parent.getContext() ).inflate( R.layout.item_search_history, null );            
          holder.remove = (ImageButton)row.findViewById( R.id.ib_search_history_remove );
  
          …
  
          holder.remove.setFocusable( false );
  
          holder.remove.setOnClickListener( removeClick );
  
          row.setTag( holder );
      } else {
          holder = (ContentHolder)row.getTag();
      }
  
      holder.remove.setTag( item );
  
  …
  
      return row;
  }
  
   private View.OnClickListener removeClick = new View.OnClickListener() {
      @Override
      public void onClick( final View view ){
          final SearchItem item = (SearchItem)view.getTag();
          final View itemView = (View)view.getParent().getParent();
  
          Animation animation = AnimationUtils.loadAnimation( view.getContext(), R.anim.attributes_disappear );
          animation.setAnimationListener( new Animation.AnimationListener() {
              @Override
              public void onAnimationStart( final Animation animation ){ }
  
              @Override
              public void onAnimationEnd( final Animation animation ){
                  list.remove( item );
             notifyDataSetChanged();
              }
  
              @Override
              public void onAnimationRepeat( final Animation animation ){ }
          } );
  
          itemView.startAnimation( animation );
      }
  };
  
  static class ContentHolder {
      TextView    name;
      TextView    category;
      TextView    description;
      TextView    number;
      ImageButton remove;
  }
  
  public static class SearchItem {
      ...
  }
  }
  </code></pre>
  
  <p>The ListView has both header and footer views.</p>