title: Simple Adapter, Invalid index when filtering
body: <p>I'm populating a listview with data from a database, it includes Images as well as text. So I can't actually filter the data then pass it to the listview. I have to filter the listview it's self. I have populated the listview using a simple adapter and images load. The problem is when filtering the list view it crashes.(See logcat).</p>
  
  <p>Code I'm using:</p>
  
  <p>Custom Simple Adapter to handle the images</p>
  
  <pre><code>public class ExtendedSimpleAdapter extends SimpleAdapter{
      List&lt;HashMap&lt;String, String&gt;&gt; map;
      String[] from;
      int layout;
      int[] to;
      Context context;
      LayoutInflater mInflater;
  
      public ExtendedSimpleAdapter(Context context, ArrayList&lt;HashMap&lt;String, String&gt;&gt; data,
                                   int resource, String[] from, int[] to) {
          super(context, data, resource, from, to);
          layout = resource;
          map = data;
          this.from = from;
          this.to = to;
          this.context = context;
      }
  
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          return this.createViewFromResource(position, convertView, parent, layout);
  
      }
  
      private View createViewFromResource(int position, View convertView,
                                          ViewGroup parent, int resource) {
          View v;
          if (convertView == null) {
              v = mInflater.inflate(resource, parent, false);
          } else {
              v = convertView;
          }
  
          this.bindView(position, v);
  
          return v;
      }
  
  
      private void bindView(int position, View view) {
          final Map dataSet = map.get(position);
          if (dataSet == null) {
              return;
          }
  
          final ViewBinder binder = super.getViewBinder();
          final int count = to.length;
  
          for (int i = 0; i &lt; count; i++) {
              final View v = view.findViewById(to[i]);
              if (v != null) {
                  final Object data = dataSet.get(from[i]);
                  String text = data == null ? "" : data.toString();
                  if (text == null) {
                      text = "";
                  }
  
                  boolean bound = false;
                  if (binder != null) {
                      bound = binder.setViewValue(v, data, text);
                  }
  
                  if (!bound) {
                      if (v instanceof Checkable) {
                          if (data instanceof Boolean) {
                              ((Checkable) v).setChecked((Boolean) data);
                          } else if (v instanceof TextView) {
                              // Note: keep the instanceof TextView check at the bottom of these
                              // ifs since a lot of views are TextViews (e.g. CheckBoxes).
                              setViewText((TextView) v, text);
                          } else {
                              throw new IllegalStateException(v.getClass().getName() +
                                      " should be bound to a Boolean, not a " +
                                      (data == null ? "&lt;unknown type&gt;" : data.getClass()));
                          }
                      } else if (v instanceof TextView) {
                          // Note: keep the instanceof TextView check at the bottom of these
                          // ifs since a lot of views are TextViews (e.g. CheckBoxes).
                          setViewText((TextView) v, text);
                      } else if (v instanceof ImageView) {
                          if (data instanceof Integer) {
                              setViewImage((ImageView) v, (Integer) data);
                          } else if (data instanceof String) {
                              setViewImage((ImageView) v, (String) data);
                          } else {
                              setViewImage((ImageView) v, text);
                          }
  
                      } else {
                          throw new IllegalStateException(v.getClass().getName() + " is not a " +
                                  " view that can be bounds by this SimpleAdapter");
                      }
                  }
              }
          }
      }
  
  
      @Override
      public int getCount() {
          return super.getCount();
      }
  
      public void setViewImage(ImageView v, String bmp) {
          v.setImageBitmap(ImageTools.decodeBase64(bmp));
      }
  
  }
  </code></pre>
  
  <p>Calling that class:</p>
  
  <pre><code>  adapter = new ExtendedSimpleAdapter(
                  getActivity(), doctorsList,
                  R.layout.listview_item_layout_doctor,
                  new String[]{KEY_ID, KEY_NAME, KEY_SPECIALTY, KEY_RATING, KEY_ACCOUNT, KEY_ACTIVE, KEY_IMAGE},
  
                  new int[]{R.id.id, R.id.fname, R.id.Specialty, R.id.Rating, R.id.Account, R.id.Active, R.id.doctorImage});
  </code></pre>
  
  <p>Logcat:</p>
  
  <pre><code>java.lang.IndexOutOfBoundsException: Invalid index 2, size is 2
              at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
              at java.util.ArrayList.get(ArrayList.java:308)
              at my.app.adapters.ExtendedSimpleAdapter.bindView(ExtendedSimpleAdapter.java:61)
              at my.app.adapters.ExtendedSimpleAdapter.createViewFromResource(ExtendedSimpleAdapter.java:54)
              at my.app.adapters.ExtendedSimpleAdapter.getView(ExtendedSimpleAdapter.java:41)
  </code></pre>