title: Adding a custom view multiple times in a layout
body: <p>I have a custom XML file. I want to repeat this in a layout (say Relative) n number of times, dynamically (obviously). </p>
  
  <p>I have seen many posts, but none helped. I am not looking for a <code>ListView</code> or <code>Adapters</code> or so. It's as simple as - A <code>RelativeLayout</code>. Inside it, adding the custom XML one above another. Any number of times. </p>
  
  <p>With a static <code>LinearLayout</code> (Vertical orientation), adding the view dynamically results in rendering it once, not one below another. Don't know why. Although a <code>TextView</code> or so do repeat one below the other in a loop inside a <code>LinearLayout</code> (Vertical).</p>
  
  <p>Then I dynamically created the layout (Relative), and inflated the custom XML. Displayed one. When I tried for another below the first it told me to remove child's parent first (Exception). If I do that and add again, its as good as removing the first rendered view and adding it again. </p>
  
  <p>So how can I get multiple views in same layout?</p>
  
  <p>A rough presentation of what I've attempted:</p>
  
  <pre><code> mainLayout = (RelativeLayout)findViewById(R.id.mainlay); //Mainlayout containing some views already
  
          params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                  ViewGroup.LayoutParams.WRAP_CONTENT);
          params.addRule(RelativeLayout.BELOW,R.id.sideLayout); //sideLayout is an existing LinearLayout within the main layout.
  
  
  
          View child = getLayoutInflater().inflate(R.layout.dynamiccustomlayout,null);
  
          RelativeLayout r1 = new RelativeLayout(this);
  
          r1.setLayoutParams(params);
          r1.addView(child);
          mainLayout.addView(r1);
          mainLayout.setLayoutParams(params);
          mainLayout.addView( child);
         /* r2 = new RelativeLayout(this);
          r2.setLayoutParams(params);
          r2.addView(contentLayout); [Gives exception] */ 
  </code></pre>