title: Avoiding having to instantiate and add child views during getView() method of android adapter
body: <p><strong>The scenario</strong></p>
  
  <p>I'm trying the create something akin to the featured page on Google Play Store. But instead of showing three items for a category I'm allowing it show any number of items in a two column <a href="https://camo.githubusercontent.com/793b5097f8e2b9823744d1ed9bcdc2ed07bdb2d2/687474703a2f2f662e636c2e6c792f6974656d732f3149306e33693336316f335230373079336b34362f3334303631365f313335353738393735312e6a706567" rel="nofollow">staggered grid view</a> fashion.</p>
  
  <p>So each list item has a header that has a title and a description followed by a custom view (lets call this SVG, as in Staggered View Group) that shows some number of children views in a staggered grid view fashion.</p>
  
  <p>I have a class called <code>FeaturedItems</code> that hold the data for a row in the featured list. Here is an extract:</p>
  
  <pre><code>public class FeaturedItems {
  
  private String mName;
  private String mDescription;
  private ArrayList&lt;Object&gt; mList;
  
  public FeaturedItems(String name, String description, Object... items) {
      mName = name;
      mDescription = description;
      mList = new ArrayList&lt;Object&gt;();
      for (int i = 0; i &lt; items.length; i++) {
          mList.add(items[i]);
  
      }
  }
  
  public int getItemCount() {
      return mList.size();
  }
  
  public Object getItem(int position) {
      return mList.get(position);
  }
  
  public String getFeatureName() {
      return mName;
  }
  
  public String getFeatureDescription() {
      return mDescription;
  }
  
  }
  </code></pre>
  
  <p>The <code>FeaturedListAdapter</code> binds the data with the views in the <code>getView()</code> method of the adapter. The <code>getView()</code> method is as follows:</p>
  
  <pre><code>@Override
  public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder;
      FeaturedItems items = getItem(position);
  
      if (convertView == null) {
          LayoutInflater infalInflater = (LayoutInflater) this.mContext
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          convertView = infalInflater.inflate(mResource, null);
  
          holder = new ViewHolder();
          holder.title = (TextView) convertView.findViewById(R.id.list_item_shop_featured_title);
          holder.description = (TextView) convertView.findViewById(R.id.list_item_shop_featured_description);
          holder.svg = (StaggeredViewGroup) convertView.findViewById(R.id.list_item_shop_featured_staggered_view);
          convertView.setTag(holder);
      } else {
          holder = (ViewHolder) convertView.getTag();
      }
  
      holder.title.setText(items.getFeatureName());
      holder.description.setText(items.getFeatureDescription());
  
      // HELP NEEDED HERE
      // THE FOLLOWING PART IS VERY INEFFICIENT
      holder.svg.removeAllViews();
  
      for (int i = 0; i &lt; items.getItemCount(); i++) {
              FeaturedItem item = new FeaturedItem(mContext, items.getItem(i));
              item.setOnShopActionsListener((ShopActions) mContext);
              holder.svg.addView(item);
      }
  
      return convertView;
  }
  </code></pre>
  
  <p><strong>The problem</strong></p>
  
  <p>In the <code>getView()</code> method, each time a view is returned, it removes all the child views in the SVG and instantiates new views called <code>FeaturedItem</code> that are then added to the SVG. Even if the SVG in a particular row, say first row, was populated, when the user scrolls back to it from the bottom, the <code>getView()</code> method will remove all the children views in the SVG and instantiates new views to be populated with.</p>
  
  <p>The inefficiency here is very obvious, and the list view animation skips frames when scrolled quite often.</p>
  
  <p>I can't just reuse the <code>convertView</code> here because it shows the wrong featured items in the <code>StaggeredViewGroup</code>. Therefore I have to remove all children from the <code>StaggeredViewGroup</code> and instantiate and add the views that are relevant to the current position.</p>
  
  <p><strong>The question</strong></p>
  
  <p>Is there a way around this problem? Or are there some alternative approaches to creating a page similar to the Google Play Store featured page, but with each row having different number of featured items thus having its unique height?</p>