title: adding one more view in the middle of the listview
body: <p>I'm trying to put multiple views into a listview, but even when i use getItemViewType() and getViewTypeCount), it doesn't work, the error is : "ArrayIndexOutofBoundsException length=2; index=2;</p>
  
  <p>Here's my code :</p>
  
  <pre><code>public class SearchAdapter extends BaseAdapter {
  private static final int TYPE_MOVIE = 1;
  private static final int TYPE_ADS = 2;
  private Context context;
  private List&lt;MovieObject&gt; movies;
  private LayoutInflater inflater;
  
  public SearchAdapter(Context context, List&lt;MovieObject&gt; movies) {
      this.context = context;
      this.movies = movies;
      inflater = (LayoutInflater) context
              .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  }
  
  @Override
  public int getViewTypeCount() {
      // TODO Auto-generated method stub
      return 2;
  }
  
  @Override
  public int getItemViewType(int position) {
      int separator = (movies.size() / 2) + 1;
      if (position == separator) {
          return TYPE_ADS;
      } else {
          return TYPE_MOVIE;
      }
  }
  
  @Override
  public int getCount() {
      // TODO Auto-generated method stub
      return movies.size();
  }
  
  @Override
  public Object getItem(int position) {
      // TODO Auto-generated method stub
      return movies.get(position);
  }
  
  @Override
  public long getItemId(int position) {
      // TODO Auto-generated method stub
      return 0;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      int type = getItemViewType(position);
      View v = convertView;
      ViewHolder h = null;
      ViewHolderAds h2 = null;
      if (v == null) {
          h = new ViewHolder();
          switch (type) {
          case TYPE_MOVIE:
              v = inflater.inflate(R.layout.adapter_search, null);
              h = new ViewHolder();
              break;
          case TYPE_ADS:
              v = inflater.inflate(R.layout.view_ads, null);
              h2 = new ViewHolderAds();
              v.setTag(h2);
              break;
          default:
              break;
          }
          v.setTag(h);
      } else {
          if (type == TYPE_MOVIE) {
              h = (ViewHolder) v.getTag();
          } else {
              h2 = (ViewHolderAds) v.getTag();
          }
  
      }
      return v;
  }
  
  private class ViewHolder {
      TextView tv_title, tv_date, tv_certification, tv_runtime;
  }
  
  private class ViewHolderAds {
  
  }
  }
  </code></pre>