title: ListView not visible in ViewPager in custom ViewGroup
body: <p>I have a custom <code>ViewGroup</code> that has a <code>ViewPager</code> as a child. This is because I want to add a static header to the <code>ViewPager</code> and mess with <code>onDraw()</code> to make the header scroll vertically with the <code>ViewPager</code> content. My <code>ViewPager</code> has a <code>ListView</code> as a child. I'm able to create the <code>ListView</code> and the adapter and even set the adapter to the <code>ListView</code>. When I read <code>wallList.getAdapter().getItemAt(0).toString()</code> it returns the data I would expect it to return. But for some reason, I can't see the <code>ListView</code> at all.</p>
  
  <p>The <code>ViewPager</code> still works as intended and the other four pages have arbitrary text for the time being. But the center page which is supposed to contain the <code>ListView</code> shows a blank screen. I can't figure out what's going on, but it sounds similar to a problem I had before <a href="https://stackoverflow.com/questions/14993439/calling-setadapter-in-facebook-oncomplete">here</a> and was able to hack my way to get something acceptable, but wasn't able to answer my original question.</p>
  
  <p>It seems like you can only call <code>setAdapter()</code> in certain places, not only does it have to be on the UI thread (I think) but it seems to have trouble doing it within certain methods, custom or overrided. Here's my custom ViewGroup code.</p>
  
  <pre><code>public class CustomProfilePager extends ViewGroup{
  
  Bitmap coverPhoto, profilePhoto;
  Paint coverStyle, profileStyle;
  String name;
  int coverHeight;
  ViewPager pager;
  ProfilePagerAdapter pagerAdapter;
  ListView wallList;
  Context context;
  
  public CustomProfilePager(Context context, AttributeSet attrs) {
      super(context, attrs);
      this.context = context;
  }
  
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
      Log.i("CustomPager", "calling onLayout()");
      pager.layout(0, coverHeight+240, getWidth(), getHeight());
  //      for(int i=0; i&lt;getChildCount(); i++){
  //          getChildAt(i).layout(l, t, r, b);
  //      }
  }
  
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  }
  
  @Override
  protected void onDraw(Canvas canvas) {
      Log.i("CustomPager", "calling onDraw()");
      super.onDraw(canvas);
      if(coverPhoto!=null){
          canvas.drawBitmap(coverPhoto, 0, 0, coverStyle);
      }
  }
  
  public void init(String name){
      Log.i("CustomPager", "calling init()");
      this.name = name;
      coverStyle = new Paint();
      coverHeight = (int) (getWidth()/2.7);
      profileStyle = new Paint();
      wallList = new ListView(context);
      pagerAdapter = new ProfilePagerAdapter();
      pager = new ViewPager(context);
      pager.setAdapter(pagerAdapter);
      addView(pager);
      pager.setCurrentItem(2);
      pager.setOffscreenPageLimit(4);
  }
  
  public void setCoverPhoto(Bitmap bitmap){
      Log.i("CustomPager", "calling setCoverPhoto()");
      int initialWidth = bitmap.getWidth();
      int initialHeight = bitmap.getHeight();
      int finalHeight = (int) (initialWidth/2.7);
      int initialYoffset = (int) (initialHeight-finalHeight)/2;
      this.coverPhoto = Bitmap.createBitmap(bitmap, 0, initialYoffset, bitmap.getWidth(), finalHeight);
      invalidate();
  }
  
  public void setProfilePhoto(Bitmap bitmap){
      this.profilePhoto = bitmap;
  }
  
  public ViewPager getViewPager(){
      return pager;
  }
  
  public void setWallAdapter(Profile.WallAdapter adapter){
      Log.i("CustomPager", "calling setWallAdapter()");
      wallList.setAdapter(adapter);
  }
  
  public class ProfilePagerAdapter extends PagerAdapter {
      @Override
      public void destroyItem(ViewGroup collection, int position, Object view) {
          ((ViewPager) collection).removeView((View) view);
      }
      @Override
      public Object instantiateItem(ViewGroup collection, int position) {
          ViewPager parent = (ViewPager) collection;
          switch (position) {
          case 2: // Wall
              wallList.setDividerHeight(0);
              parent.addView(wallList);
              return wallList;
          default:
              TextView testText = new TextView(context);
              testText.setText(String.valueOf(position) + ": " + name);
              testText.setTextSize(46);
              testText.setGravity(Gravity.CENTER);
              parent.addView(testText);
              return testText;
          }
      }
      @Override
      public int getCount() {
          return 5;
      }
      @Override
      public boolean isViewFromObject(View view, Object object) {
          return view == object;
      }
  }
  </code></pre>
  
  <p>}</p>