title: Adding multiple TextView(s) in a LinearLayout causes stackOverflowError
body: <p>I need to add multiple <code>TextViews</code> to a <code>LinearLayout</code>.</p>
  
  <p>But the code is creating some kind of cyclic dependency which is causing <code>stackOverflowError</code>.</p>
  
  <pre><code> LinearLayout tagsLayout;
   tagsLayout = (LinearLayout) rootView.findViewById(R.id.pager_item_tags);
  
    if (!tagsArrayList.isEmpty()) {
        TextView tagTitle = new TextView(context);
        tagTitle.setText("Tags: ");
        tagsLayout.addView(tagTitle, 0);
        TextView tagsTextView = new TextView(context);
        tagsTextView.setGravity(TextView.TEXT_ALIGNMENT_CENTER);
        tagsTextView.setBackgroundResource(R.drawable.bg_tag);                            
        tagsTextView.setTextColor(context.getResources().getColor(R.color.ColorWhite));
        tagsTextView.setPadding(4, 0, 4, 0);
  
        for (Tags tags : tagsArrayList) {
            tagsTextView.setText(tags.getName());
  
           /*generating some kind of cyclic dependency*/
  
          if (tagsTextView.getParent() != null) {
              ((ViewGroup) tagsTextView.getParent()).removeView(tagsTextView);
          }
  
          tagsLayout.addView(tagsTextView);
       }
  
    }
  </code></pre>
  
  <p>If I do not use <code>getParent().removeView()</code>
  I get <code>java.lang.IllegalStateException you must call removeView() on the child's parent first.</code>
  I need to display <em>tags</em> which varies in number so, I can't use <strong>xml</strong> to achieve the desired result.</p>
  
  <p>Thanks for your help.</p>
  
  <p><strong>StackTrace:</strong></p>
  
  <pre><code>  java.lang.StackOverflowError: stack size 8MB
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6081)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
              at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6082)
  
  
          android.os.TransactionTooLargeException
              at android.os.BinderProxy.transactNative(Native Method)
              at android.os.BinderProxy.transact(Binder.java:496)
              at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:4105)
              at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:89)
              at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
              at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
  </code></pre>