title: custom view doesn't draw in a custom viewgroup
body: <p>I'm developing a test to try to understand the behaviour of views and viewgroups. I've created a very simple custom viewgroup (hereafter viewgroup1), I've implemented correctly all the importants methods (onLayout, onMeasure, onSizeChanged). Then I've created a simple view and I add the view to viewgroup1 from a onclick event. The view is showed correctly and its methods are invoked (onSizeChanged, onLayout, onDraw).</p>
  
  <p>After that successful test, I've created another custom viewgroup (hereafter viewgroup2) and this time I've added viewgroup2 to viewgroup1. Then I've added the custom view to viewgroup2 from the onclick event. I expected everything to happen as in the first test but when I click on viewgroup2, the view is added to this one, however only viewgroup1 methods are invoked (onMeasure, onLayout). The calls are not propagated down the inheritance tree.</p>
  
  <p>The result is that the tree structure is correct, but the view isn't showed despite I've invoked the requestLayout, forcelayout and so on for every object.</p>
  
  <p>The tree structure is: viewgroup1---viewgroup2---view.</p>
  
  <p>Manifest code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.yoredevelopment.tests"
      android:versionCode="1"
      android:versionName="1.0" &gt;
      &lt;uses-sdk android:minSdkVersion="11" /&gt;
      &lt;application
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name" &gt;
          &lt;activity
              android:name=".AndroidTestsActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Layout code (main.xml):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:custom="http://schemas.android.com/apk/res/com.yoredevelopment.tests"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="#ff000000"
      android:orientation="vertical" &gt;
          &lt;com.yoredevelopment.tests.TestViewGroup
                  android:id="@+id/TestViewGroup"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:background="#ff00cccc"
                  /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Activity code:</p>
  
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  
  public class AndroidTestsActivity extends Activity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
      }
  }
  </code></pre>
  
  <p>View and ViewGroups code:</p>
  
  <pre><code>import android.content.Context;
  import android.graphics.Canvas;
  import android.graphics.Color;
  import android.graphics.Paint;
  import android.graphics.Paint.Style;
  import android.util.AttributeSet;
  import android.view.View;
  import android.view.ViewGroup;
  
  public class TestViewGroup extends ViewGroup {
      public TestViewGroup(Context context, AttributeSet attrs) {
          super(context, attrs);
          TestViewChild tvc = new TestViewChild(context);
          tvc.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
          tvc.setBackgroundColor(Color.WHITE);
          this.addView(tvc);
      }
  
      protected void onLayout(boolean changed, int l, int t, int r, int b) {
          if(this.getChildCount() &gt; 0) {
              View child = this.getChildAt(0);
              View p = (View)this.getParent();
              child.layout(20, 20, p.getWidth() - 40, p.getHeight() - 40);
          }
      }
  
      protected void onSizeChanged(int w, int h, int oldw, int oldh) {
          super.onSizeChanged(w, h, oldw, oldh);
      }
  
      class TestViewChild extends ViewGroup {
          public TestViewChild(Context context) {
              super(context);
              this.setOnClickListener(new TestClickListener());
          }
  
          protected void onLayout(boolean changed, int l, int t, int r, int b) {
              if(this.getChildCount() &gt; 0) {
                  View child = this.getChildAt(0);
                  child.layout(10, 10, 40, 40);
              }
          }
  
          protected void onSizeChanged(int w, int h, int oldw, int oldh) {
              super.onSizeChanged(w, h, oldw, oldh);
          }
      }
  
      class TestView extends View {
          private Paint p;
          public TestView(Context context) {
              super(context);
              p = new Paint();
              p.setColor(Color.RED);
              p.setStyle(Style.FILL);
          }
  
          protected void onDraw(Canvas canvas) {
              super.onDraw(canvas);
              int centerX = this.getWidth() / 2;
              int centerY = this.getHeight() / 2;
              canvas.drawCircle(centerX, centerY, 5, this.p);
          }
  
          protected void onLayout(boolean changed, int l, int t, int r, int b) {
              super.onLayout(changed, l, t, r, b);
          }
  
          protected void onSizeChanged(int w, int h, int oldw, int oldh) {
              super.onSizeChanged(w, h, oldw, oldh);
          }
      }
  
      class TestClickListener implements OnClickListener {
          public void onClick(View v) {
              ViewGroup vg = (ViewGroup)v;
              TestView tv = new TestView(vg.getContext());
              tv.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
              tv.setBackgroundColor(Color.GREEN);
              vg.addView(tv);
              tv.bringToFront();
          }
      }
  }
  </code></pre>
  
  <p>If I create the View in the ViewGroup2 constructor, the view is showed but it doesn't happen when the view is created from the onclick event.</p>
  
  <p>Thanks in advance and have a good holiday.</p>