title: Reusing views in Android Listview with 2 different layouts
body: <p>I've learned that to maximize efficiency with Android listviews, you should only have as many inflated 'row' views as are needed to fit on the screen. Once a view has moved off the screen, you should reuse it in your <code>getView</code> method, checking if <code>convertView</code> is null or not.</p>
  
  <p>However, how can you implement this idea when you need 2 different layouts for the list? Lets say its a list of orders and 1 layout is for completed orders and the other layout is for in process orders.</p>
  
  <p>This is an example tutorial of the idea my code is using. In my case, I would have 2 row layouts: <code>R.layout.listview_item_product_complete</code> and <code>R.layout.listview_item_product_inprocess</code></p>
  
  <pre><code>public View getView(int position, View convertView, ViewGroup parent) {
  
  ViewHolder holder = null;
  
  if (convertView == null) {
      holder = new ViewHolder();
      if(getItemViewType(position) == COMPLETE_TYPE_INDEX) {
          convertView = mInflator.inflate(R.layout.listview_item_product_complete, null);
          holder.mNameTextView = (TextView) convertView.findViewById(R.list.text_complete);
          holder.mImgImageView = (ImageView) convertView.findViewById(R.list.img_complete);
      }
      else { // must be INPROCESS_TYPE_INDEX
          convertView = mInflator.inflate(R.layout.listview_item_product_inprocess, null);
          holder.mNameTextView = (TextView) convertView.findViewById(R.list.text_inprocess);
          holder.mImgImageView = (ImageView) convertView.findViewById(R.list.img_inprocess);
      }
      convertView.setTag(holder);
  } else {
      holder = (ViewHolder) convertView.getTag();
  }
      thisOrder = (Order) myOrders.getOrderList().get(position);
      // If using different views for each type, use an if statement to test for type, like above
      holder.mNameTextView.setText(thisOrder.getNameValue());
      holder.mImgImageView.setImageResource(thisOrder.getIconValue());
      return convertView;
  }
  
  public static class ViewHolder {
      public TextView mNameTextView;
      public ImageView mImgImageView;
  }
  </code></pre>