title: Android: Add two text views programmatically
body: <p>I am trying  to add Views to a linear layout programmatically.</p>
  
  <pre><code>    LinearLayout layout     = (LinearLayout) findViewById(R.id.info);
      String [] informations  = topOffer.getInformations();
      TextView informationView;
      View line = new View(this);
      line.setLayoutParams(new LayoutParams(1, LayoutParams.FILL_PARENT));
      line.setBackgroundColor(R.color.solid_history_grey);
      for (int i = 0; i &lt; informations.length; i++) {
          informationView = new TextView(this);
          informationView.setText(informations[i]);
          layout.addView(informationView, 0);
          layout.addView(line, 1);
      }
  </code></pre>
  
  <p>First, I have only added the informationsView, and everything worked fine. Butt after adding also the line-View, it crashed with the following error:</p>
  
  <p>java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.</p>
  
  <p>So I tried addView(View v, int index), but it crashed with the same message...</p>
  
  <p>Has somebody a solution?</p>
  
  <p>Thanks,
  Martin</p>