title: Android ViewPager children not shown when instantiated using a composite widget rather than an inflated layout
body: <p>I have an interesting quirk that I can't figure my way around. So I wrapped my layout around a widget so I could add some events and other convenient methods. However, using the constructor of the widget, I am unable to instantiate it as a child in a ViewPager. If I however, inflate the layout without the widget wrapper, it works.</p>
  
  <p>Heres the code that works: (The one that doesn't work is commented out)</p>
  
  <pre><code>private View getNewTabView() {
      View view = getLayoutInflater().inflate(
              R.layout.checkpoint_new_tab_view, null);
  
      // XmlPullParser parser = getResources().getXml(
      // R.layout.checkpoint_new_tab_view);
      // AttributeSet as = Xml.asAttributeSet(parser);
      // NewCheckpointsTabVIew view = new NewCheckpointsTabVIew(this, as);
      return view;
  }
  </code></pre>
  
  <p>Here's my adapter code for my ViewPager</p>
  
  <pre><code>private class CheckpointPagerAdapter extends PagerAdapter {
  
      @Override
      public void destroyItem(View collection, int position, Object view) {
          ((ViewPager) collection).removeView((ScrollView) view);
      }
  
      @Override
      public void finishUpdate(View arg0) {
      }
  
      @Override
      public int getCount() {
          return 4;
      }
  
      @Override
      public Object instantiateItem(View arg0, int arg1) {
          View child = getNewTabView();
          ((ViewPager) arg0).addView(child, 0);
          return child;
      }
  
      @Override
      public boolean isViewFromObject(View view, Object object) {
          return view == object;
      }
  
      @Override
      public void restoreState(Parcelable arg0, ClassLoader arg1) {
      }
  
      @Override
      public Parcelable saveState() {
          return null;
      }
  
      @Override
      public void startUpdate(View arg0) {
      }
  
  }
  </code></pre>
  
  <p>And heres the wrapper for the widget that wraps around the inflated layout:</p>
  
  <pre><code>public class NewCheckpointsTabVIew extends ScrollView {
  
      Context context;
  
      public NewCheckpointsTabVIew(Context context) {
          super(context);
          this.context = context;
      }
  
      public NewCheckpointsTabVIew(Context context, AttributeSet attrs) {
          super(context, attrs);
          this.context = context;
      }
  
      private void init() {
          // height + width
          android.view.ViewGroup.LayoutParams params = getLayoutParams();
          params.height = android.view.ViewGroup.LayoutParams.FILL_PARENT;
          params.width = android.view.ViewGroup.LayoutParams.FILL_PARENT;
          setLayoutParams(params);
      }
  
      @Override
      public void onFinishInflate() {
          super.onFinishInflate();
          LayoutInflater layoutInflater = (LayoutInflater) getContext()
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          layoutInflater.inflate(R.layout.checkpoint_new_tab_view, this);
      }
  
      @Override
      public void onSizeChanged(int w, int h, int oldw, int oldh) {
          super.onSizeChanged(w, h, oldw, oldh);
          init();
      }
  
  }
  </code></pre>
  
  <p>Does anyone know why? Thanks!</p>