title: RecyclerView ViewHolder with programmatically added views in LinearLayout gives error "You must call removeView() on the child's parent first"
body: <p>I am using a <code>RecyclerView.ViewHolder</code> being used in a <code>RecyclerView</code>. In this viewholder, I have a <code>LinearLayout</code> which I am programmatically adding views to, the container.</p>
  
  <p>When I run it I get this error:</p>
  
  <pre><code>02-09 19:15:57.532 23106-23106/com.fusionprojects.edmodo E/AndroidRuntime: FATAL EXCEPTION:main
  
  java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
  at android.view.ViewGroup.addViewInner(ViewGroup.java:3339)
  at android.view.ViewGroup.addView(ViewGroup.java:3210)
  at android.view.ViewGroup.addView(ViewGroup.java:3155)
  at android.view.ViewGroup.addView(ViewGroup.java:3131)
  at com.edmodo.stream.PostAttachmentsViewHolder.showFileAttachments(PostAttachmentsViewHolder.java:117)
  at com.edmodo.stream.PostAttachmentsViewHolder.setAttachments(PostAttachmentsViewHolder.java:75)
  at com.edmodo.stream.StreamPostViewHolder.setPost(StreamPostViewHolder.java:47)
  at com.edmodo.postsstream.PostStreamAdapter.onBindViewHolder(PostStreamAdapter.java:49)
  at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:4138)
  at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3448)
  at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3340)
  at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1810)
  at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1306)
  at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1269)
  at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:523)
  at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:1988)
  at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:2237)
  at android.view.View.layout(View.java:14003)
  at android.view.ViewGroup.layout(ViewGroup.java:4375)
  at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:543)
  at android.view.View.layout(View.java:14003)
  at android.view.ViewGroup.layout(ViewGroup.java:4375)
  at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  at android.view.View.layout(View.java:14003)
  at android.view.ViewGroup.layout(ViewGroup.java:4375)
  at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  at android.view.View.layout(View.java:14003)
  at android.view.ViewGroup.layout(ViewGroup.java:4375)
  at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  at android.view.View.layout(View.java:14003)
  at android.view.ViewGroup.layout(ViewGroup.java:4375)
  at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:890)
  at android.view.View.layout(View.java:14003)
  at android.view.ViewGroup.layout(ViewGroup.java:4375)
  at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  at android.view.View.layout(View.java:14003)
  at android.view.ViewGroup.layout(ViewGroup.java:4375)
  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
  at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
  at android.view.View.layout(View.java:14003)
  at android.view.ViewGroup.layout(ViewGroup.java:4375)
  at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  at android.view.View.layout(View.java:14003)
  at android.view.ViewGroup.layout(ViewGroup.java:4375)
  at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892)
  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711)
  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
  at android.view.Choreographer.doCallbacks(Choreographer.java:562)
  at android.view.Choreographer.doFrame(Choreographer.java:532)
  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
  at android.os.Handler.handleCallback(Handler.java:725)
  at android.os.Handler.dispatchMessage(Handler.java:92)
  at android.os.Looper.loop(Looper.java:137)
  at android.app.ActivityThread.main(ActivityThread.java:5039)                       
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.
  </code></pre>
  
  <p>I have tried calling <code>removeAllViews()</code> and looping through the <code>LinearLayout</code>'s children and removing each other individually, but I still get the same error.</p>
  
  <p>How can I handle this and properly remove all the views in the LinearLayout container?</p>