title: Android how to display only some fields of a layout
body: <p>I am trying to have one layout file with two text views and depending on a dynamic condition, I want to choose how many text fields to display. 
  The attached code shows both the fields all the time :-(
  The motivation behind such design is to avoid maintaining two activities and later divergence of look and feel.
  Any help is appreciated.</p>
  
  <p>The code to call text view creations, where m is decided as <code>0</code> or <code>1</code> based on other UI events. The goal is to display <code>m</code> number of text views:</p>
  
  <pre><code>    for (int i = 0; i &lt; m; i++) {
          b = new B_ContactCollector(this, i);
          c.add(i, b);
      }
  </code></pre>
  
  <p>The code to create the text views</p>
  
  <pre><code>    switch (n) {
      case 0:
          tv = (TextView) f.findViewById(R.id.tv1);
          b = (Button) f.findViewById(R.id.button1);
          b.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View arg0) {
                  // get a new Contact
                  Intent i = new Intent (f, B_ContactLister.class);
                  i.putExtra("windowNumber", 0);
                  f.startActivityForResult(i,1);
              }
          }); 
          break;
      case 1: 
          tv = (TextView) f.findViewById(R.id.tv2);
          b = (Button) f.findViewById(R.id.button2);  
          b.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View arg0) {
                  // get a new Contact
                  Intent i = new Intent (f, B_ContactLister.class);
                  i.putExtra("windowNumber", 1);
                  f.startActivityForResult(i,1);
              }
          }); 
          break;
      default:
          // throw an error that it shouldn't have come here  
          break;
      }
  </code></pre>
  
  <p>The layout is:
      </p>
  
  <pre><code>&lt;TextView
      android:id="@+id/tv1"
      android:layout_width="fill_parent"
      android:layout_height="180dp"
      android:layout_alignLeft="@+id/tv2"
      android:layout_alignParentTop="true"
      android:background="#FF9D85"
      android:maxLines="5"
      android:scrollbars="vertical" /&gt;
  
  &lt;Button
      android:id="@+id/button1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignBottom="@+id/tv1"
      android:text="+" /&gt;
  
  &lt;TextView
      android:id="@+id/tv2"
      android:layout_width="fill_parent"
      android:layout_height="180dp"
      android:layout_alignLeft="@+id/button1"
      android:layout_below="@+id/tv1"
      android:layout_marginTop="20dp"
      android:background="#FF9D85"
      android:maxLines="5"
      android:scrollbars="vertical" /&gt;
   &lt;Button
      android:id="@+id/button2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignBottom="@+id/tv2"
      android:layout_alignLeft="@+id/tv2"
      android:text="+" /&gt;
  
  &lt;ImageView
      android:id="@+id/intro"
      android:layout_width="150dp"
      android:layout_height="30dp"
      android:layout_alignParentBottom="true"
      android:layout_centerHorizontal="true"
      android:src="@drawable/intro" /&gt;
  </code></pre>
  
  <p></p>