title: ListViews with multiple item layouts
body: <p>I have a <code>ListView</code> on my <code>ListActivity</code> and I'd like the rows of the <code>ListView</code> to be 1 of 3 different layouts.  The first item in my list is always going to use layout A, the second item in my list is always going to use layout B, and all subsequent items are going to use layout C.</p>
  
  <p>Here is my getView function:</p>
  
  <pre><code>@Override
  public View getView(int position, View convertView, ViewGroup parent) { 
      // get the View for this list item
      View v = convertView;
      if (v == null) {
          LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          switch (position) {
              case 0:
                  v = vi.inflate(R.layout.layout_A, parent, false);
                  break;
              case 1:
                  v = vi.inflate(R.layout.layout_B, parent, false);
                  break;
              default:
                  v = vi.inflate(R.layout.layout_C, parent, false);
                  break;
          }
      }   
      switch (position) {
          case 0:
              TextView txtLabel1 = (TextView)findViewById(R.id.label1);
              TextView txtLabel2 = (TextView)findViewById(R.id.label2);
              if (txtLabel1 != null) {
                  txtLabel1.setText("sdfasd");
              }
              if (txtLabel2 != null) {
                  txtLabel2.setText("dasgfadsasd");
              }
              break;
          default:
              break;
      }
      // return the created view
      return v;
  }
  </code></pre>
  
  <p><code>R.id.label1</code> and <code>R.id.label2</code> are <code>TextViews</code> on <code>R.layout.layout_A</code>.  However, <code>txtLabel1</code> and <code>txtLabel2</code> are null after trying to set them.  Why? </p>
  
  <p>I stepped through this code in the debugger and it inflated the correct layout (<code>R.layout.layout_A</code>) and fell into the correct case below to set the <code>R.id.label1</code> and <code>R.id.label2</code> text.</p>
  
  <p>Also, if there is a better way to do this, please let me know.</p>