title: Hide items from GridView with custom ArrayAdapter
body: <p>I tried to hide some items in my GridView dynamically with this code:</p>
  
  <pre><code>public class GridHelper extends ArrayAdapter&lt;Object&gt;
  {
      private Context context; 
      private int layoutResourceId;    
  
      private ArrayList&lt;Object&gt; mainlist = null;
      private ArrayList&lt;Object&gt; sichtbar = null;
  
      public GridHelper(Context context, int layoutResourceId, ArrayList&lt;Object&gt; mainlist) 
      {
          super(context, layoutResourceId, mainlist);
  
          this.layoutResourceId = layoutResourceId;
          this.context = context;
  
          this.mainlist = mainlist;
          this.sichtbar = ArrayList&lt;Object&gt;(); 
          // that's important otherwith the items are doublicated but the items 
          // are inside the List. I think the add method is called somewhere 
          // in the super constructor
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) 
      {
          View row = convertView;
  
          if(row == null)
          {           
              LayoutInflater inflater = ((Activity)context).getLayoutInflater();
              row = inflater.inflate(layoutResourceId, null);
  
              Object t = sichtbar.get(position);
  
              if(t != null)
             {
                  row = (View) t;
             }
          }
  
          return row;
      }
  
      @Override
      public int getCount() 
      {
          return sichtbar.size();
      }
  
      @Override
      public void add(Object object)
      {
          super.add(object);
          sichtbar.add(object);
      }
  
      public void show(int pos)
      {
          if(sichtbar.contains(mainlist.get(pos)) == false)
          {
              sichtbar.add(mainlist.get(pos));
              notifyDataSetChanged();
          }
      }
  
      public void hide(int pos)
      {
          if(sichtbar.contains(mainlist.get(pos)) == true)
          {
              sichtbar.remove(mainlist.get(pos)); 
              notifyDataSetChanged();
          }
      }
  }
  </code></pre>
  
  <p>But the search function does not work. The list has the right size after my show/hide method but the first item (<code>mainlist .get(0)</code>) is allways visible and I think it covered the right item. I found out that the <code>getView</code> method is allways called one time more than the size of the list. If the list has 3 items the <code>getView</code> method is called 4 times and so on. </p>
  
  <p>The seconde thing is: If I have 3 items in my GridView and call the hide function for two items the <code>getView</code> methode is called 4 times (the old size + 1) and than again 2 times (new size + 1). That is very strange isn't it?</p>
  
  <p>Why is that? I think the logic behind it is right isn't it?</p>