title: Android custom widget based on existing widgets
body: <p>I hope my problem will be understandable because I'm a Android beginner and English is not my native.</p>
  
  <p>I would like create a custom widget which group a couple of TextView, ProgressBar and Button. The goal is to be able to declare my custom widget in a XML layout file with custom attributes which define buttons texts, etc ... But the disposition of inner Android widgets will be the same and defined in my class. </p>
  
  <p>I have found how to declare custom attributes and create a custom widget, but I didn't found any documentation nor examples in the simple case of placement of existing Android widgets. I'am surprising so maybe I search in the wrong direction.</p>
  
  <p>Below the simple code I am testing.</p>
  
  <p>Custom class :</p>
  
  <pre><code>public class CastleViewItem extends View {
  
      private TextView item;
  
      public CastleViewItem (Context c, AttributeSet attributes) {
          super(c, attributes);
          item = new TextView(c);
          TypedArray attrs = c.obtainStyledAttributes(attributes, R.styleable.CastleViewItem);
          item.setText(attrs.getString(R.styleable.CastleViewItem_name).toString());
   }
      @Override
      protected void onDraw(Canvas canvas) {
          super.onDraw(canvas); 
          // I suppose there is some code to add here.
      }
      @Override
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          setMeasuredDimension(200, 200);
          // item.getWidth()/item.getHeight() return 0, so I fixed temporarily the value to ensure 
          // the widget will be displayed.
      }
  }
  </code></pre>
  
  <p>XML custom attributes declaration :</p>
  
  <pre><code>&lt;resources&gt;
      &lt;declare-styleable name="CastleViewItem"&gt;
          &lt;attr name="name" format="string" /&gt;
      &lt;/declare-styleable&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>XML layout file :</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:ffbdx="http://schemas.android.com/apk/res/bdx.fleurey"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="horizontal" &gt;
  
      &lt;bdx.fleurey.CastleViewItem
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          ffbdx:name="Moat" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>This code display nothing.
  I hope I was quite clear, thanks in advance for your answers/advices.</p>