title: How to inflate Android View in LinearLayout class?
body: <p>I've got a little piece of xml, which I'll be using in a lot of places in my app. For this reason I want to store it in a separate file. So I created mywidget.xml in which I have my xml. I then try to inflate this in mywidget.java, after which I want to include it in a different xml file like so: </p>
  
  <p><code>&lt;com.mycom.android.ui.widget.AmountWidget android:layout_width="fill_parent" android:layout_height="wrap_content"&gt;&lt;/com.mycom.android.ui.widget.AmountWidget&gt;</code></p>
  
  <p>In my java file, I try to inflate the initial xml like this:</p>
  
  <pre><code>public class AmountWidget extends LinearLayout {
      public AmountWidget(Context context) {
          super(context);
          LinearLayout ll = (LinearLayout) findViewById(R.layout.amount_widget);
          addView(ll);
      }
  }
  </code></pre>
  
  <p>But with the code above I get an error saying that there's an error inflating class com.mycom.android.ui.widget.AmountWiget. </p>
  
  <p><strong>My question: Does anybody know how I can inflate a layout so that I can use it as a class in another xml layout file?</strong></p>
  
  <p>The xml from the widget looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content" 
      android:layout_margin="10dp"
      android:padding="10dp"
      android:background="@layout/border"
      &gt;
      &lt;EditText
          android:id="@+id/payment_amount_major"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:textSize="35sp"
          android:textStyle="bold"
          android:inputType="number"
          android:digits="0,1,2,3,4,5,6,7,8,9"
          android:maxLength="9"  
          android:gravity="right"
          /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>