title: How to Programmatically Add Views to ViewContainer?
body: <p>When I override the <code>public Object instantiateItem</code> function of <code>MainAdapter extends PagerAdapter</code> , at line <code>container.addView(</code>,it crash down. I receive the following log</p>
  
  <pre><code>java.lang.IllegalArgumentException: Cannot add a null child view to a ViewGroup
          at android.view.ViewGroup.addViewInLayout(ViewGroup.java:3909)
          at android.view.ViewGroup.addViewInLayout(ViewGroup.java:3890)
          at android.support.v4.view.ViewPager.addView(ViewPager.java:1302)
          at android.view.ViewGroup.addView(ViewGroup.java:3744)
          at com.jfeinstein.jazzyviewpager.JazzyViewPager.addView(JazzyViewPager.java:127)
          at com.ycg.bottommenuslidegradientswipe.MainActivity$MainAdapter.instantiateItem(MainActivity.java:260)
  </code></pre>
  
  <p>My code of the <code>instanstiateItem</code> function is shown below. Class <code>TaskCompletedView</code> extends <code>View</code> </p>
  
  <pre><code>@Override
  public Object instantiateItem(ViewGroup container, final int position) {
      TasksCompletedView mTasksView = (TasksCompletedView) findViewById(R.id.tasks_view);
      container.addView(mTasksView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
      jazzyPager.setObjectForPosition(mTasksView,position);
  
      new Thread(new ProgressRunable()).start();
      return mTasksView;
      }
  </code></pre>