title: Specified child already has a parent error. Only occurs if called in different loop
body: <p>I am trying to make a sort linearlayout for android. However, to sort the layout, it needs to be sorted before adding it to the layout. However, if i want to add the objects lateron, it says the child already has a parent. It seems like they are assigned a parent automatically. This is the normal code which works fine:</p>
  
  <pre><code>    post_list = new ArrayList&lt;Post&gt;();
      for(int i = 0; i &lt; 100; i++) {
          Post post = new Post(this, "#4c66a4", "#FFFFFF");
          post_list.add(post);
  
          View list = (View) post.show();
          ll.addView(list, layoutParams);
      }
  </code></pre>
  
  <p>However, when I want to add the view later, it is not possible anymore:</p>
  
  <pre><code>    post_list = new ArrayList&lt;Post&gt;();
      for(int i = 0; i &lt; 100; i++) {
          Post post = new Post(this, "#4c66a4", "#FFFFFF");
          post_list.add(post);
      }
  
      for (int i = 0; i &lt; post_list.size(); i++) {
          Post p = post_list.get(i);
          View list = (View) p.show();
          ll.addView(list, layoutParams);
  
      }
  </code></pre>
  
  <p>Any idea how this problem is caused?
  Thanks in advance</p>