title: custom view with layout
body: <p>ok,</p>
  
  <p>what i am trying to do is to embed a custom view in the default layout 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"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
  
      &lt;com.lam.customview.CustomDisplayView
          android:id="@+id/custom_display_view1"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" /&gt;
  
  
      &lt;LinearLayout
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"&gt;
  
          &lt;Button
              android:id="@+id/prev"
              android:layout_width="0dip"
              android:layout_height="wrap_content"
              android:layout_weight="50"
              android:textAppearance="?android:attr/textAppearanceSmall"
              android:text="@string/prev" /&gt;
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>as you can see the class is called com.lam.customview.CustomDisplayView, with the id of custom_display_view1.</p>
  
  <p>now in the com.lam.customview.CustomDisplayView class, i want to use another layout called custom_display_view.xml because i don't want to programmatically create controls/widgets.  </p>
  
  <p>custom_display_view.xml is just a button and an image, the content of which i want to change based on certain conditions:</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="fill_parent"
      android:layout_height="fill_parent"
      &gt;
      &lt;TextView 
      android:id="@+id/display_text_view1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/hello"
      /&gt;
      &lt;ImageView 
      android:id="@+id/display_image_view1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"&gt;
      &lt;/ImageView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>i tried to do:</p>
  
  <p>1)     </p>
  
  <pre><code>public CustomDisplayView(Context context, AttributeSet attrs) {
      super(context, attrs);
  
      try
      {
          // register our interest in hearing about changes to our surface
          SurfaceHolder holder = getHolder();
          holder.addCallback(this);
  
          View.inflate(context, R.layout.custom_display_view, null);
  </code></pre>
  
  <p>...</p>
  
  <blockquote>
    <p>but got this error, "03-08 20:33:15.711: ERROR/onCreate(10879): Binary XML file line #8: Error inflating class java.lang.reflect.Constructor
    ".</p>
  </blockquote>
  
  <p>2)     </p>
  
  <pre><code>public CustomDisplayView(Context context, AttributeSet attrs) {
      super(context, attrs);
  
      try
      {
          // register our interest in hearing about changes to our surface
          SurfaceHolder holder = getHolder();
          holder.addCallback(this);
  
          View.inflate(context, R.id.custom_display_view1, null);
  </code></pre>
  
  <p>...</p>
  
  <blockquote>
    <p>but got this error, "03-08 20:28:47.401: ERROR/CustomDisplayView(10806): Resource ID #0x7f050002 type #0x12 is not valid
    "</p>
  </blockquote>
  
  <p>also, if i do it this way, as someone has suggested, it's not clear to me how the custom_display_view.xml is associated with the custom view class.</p>
  
  <p>thanks.</p>