title: Create custom viewGroup with custom layout + one child
body: <p>I would like to create a component which would allow me to simplify a ViewFlipper.</p>
  
  <p>The first view of my flipper is a progressBar, which show to the user that the content is loading, and the second view in my flipper is my content (for example another layout). 
  In other words, I want to simplify this:</p>
  
  <pre><code>&lt;ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
      &lt;ProgressBar
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
  
      &lt;TextView
          android:id="@+id/myContent"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"  /&gt;
  
  &lt;/ViewFlipper&gt;
  </code></pre>
  
  <p>The first view (the progressBar) is always the same for all my activities, so the component I want to create could be used like that (file layout-activity.xml):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
      &lt;com.example.fred.myapplication.MyCustomComponent
          android:id="@+id/myComponent"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
  
          &lt;TextView
              android:id="@+id/myContent"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              /&gt;
  
      &lt;/com.example.fred.myapplication.MyCustomComponent&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I started to create the component like that:</p>
  
  <pre><code>public class MyCustomComponent extends RelativeLayout {
  
  ViewFlipper myFlipper;
  
  public MyCustomComponent(Context context) {
      super(context);
  }
  
  public MyCustomComponent(Context context, AttributeSet attrs) {
      super(context, attrs);
  }
  
  public MyCustomComponent(Context context, AttributeSet attrs, int defStyleAttr) {
      super(context, attrs, defStyleAttr);
  }
  
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
      super.onLayout(changed, l, t, r, b);
  
      //the main template
      View template = inflate(getContext(), R.layout.template, null);
  
      //get the viewFlipper from my template
      myFlipper = (ViewFlipper) template.findViewById(R.id.myFlipper);
  
      //add the first child of my custom component to the view flipper
      myFlipper.addView(getChildAt(0));
  }
  
  /**
   * Show the progressBar
   */
  public void showProgressBar(){
      myFlipper.setDisplayedChild(0);
  }
  /**
   * Show my custom content which can be a textview in my example but also a LinearLayout for example...
   */
  public void showContent(){
      myFlipper.setDisplayedChild(1);
  }
  }
  </code></pre>
  
  <p>And the template.xml which contains the viewFlipper is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/myFlipper"
  android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
      &lt;ProgressBar
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
  
  &lt;/ViewFlipper&gt;
  </code></pre>
  
  <p>In my activities I want to use my custom component like that:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  MyCustomComponent myCustomComponent;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.layout_activity);
  
      myCustomComponent = (MyCustomComponent) findViewById(R.id.myComponent);
      myCustomComponent.showProgressBar();
      loadLongStuff();
  }
  
  private void loadLongStuff() {
      //processing... long stuff
      //working again...
  
      //at the end, show my content loaded
      myCustomComponent.showContent();
  }
  }
  </code></pre>
  
  <p>I created each files I wrote here but it doesn't work: my app crash but I don't have any stack trace.... can you tell me what's wrong?</p>
  
  <p>Thank you.</p>