Android Custom Layout
<p>I am getting an exception while inflating my custom view.</p>

<pre><code>public class MyFirstView extends LinearLayout {

public MyFirstView(Context context) {
    super(context);
    initialize(context);

}

public MyFirstView(Context context, AttributeSet attrs) {
    super(context, attrs);
    initialize(context);
}

public MyFirstView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    initialize(context);
}

private void initialize(Context context) {

    LayoutInflater layoutInflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    layoutInflater.inflate(R.layout.edit_text_view, this);

}
</code></pre>

<p>}</p>

<pre><code>public class ContainerView extends LinearLayout {

    public ContainerView(Context context) {

        super(context);
        LayoutInflater layoutInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        layoutInflater.inflate(R.layout.item_container, this);
    }

    public ContainerView(Context context, AttributeSet attrs) {

        super(context, attrs);

        LayoutInflater layoutInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        layoutInflater.inflate(R.layout.item_container, this);
    }

    public ContainerView(Context context, AttributeSet attrs, int defStyle) {

        super(context, attrs, defStyle);
        LayoutInflater layoutInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        layoutInflater.inflate(R.layout.item_container, this);

    }

    @Override
    protected void onFinishInflate() {

        int index = getChildCount();
        View[] children = new View[index];
        while (--index &gt;= 0) {
            children[index] = getChildAt(index);
        }

        this.detachAllViewsFromParent();



        final ViewGroup newParent = (ViewGroup)LayoutInflater.from(getContext()).inflate(R.layout.item_container, this, true);


        index = children.length;
        // Push declared children into new container.


        while(--index &gt;= 0) {
            newParent.addView(children[index]);
        }
        addView(newParent);
        super.onFinishInflate();
    }

}
</code></pre>

<p>Now i have created two custom layouts this is a child layout.</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:orientation="vertical" &gt;

    &lt;LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" &gt;

        &lt;TextView
            android:id="@+id/edit_text_label"
            android:text="Hello"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:ellipsize="end"
            android:gravity="left|center_vertical"
            android:paddingBottom="10dp"
            android:paddingLeft="18dp"
            android:paddingTop="10dp"
            android:singleLine="true"
            android:textColorHint="#778BB0"
            android:textSize="16.0sp"
            android:typeface="sans"
            android:textStyle="bold" /&gt;

        &lt;EditText
             android:text="Hello"
            android:id="@+id/edit_text"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="2"
            android:background="@null"
            android:ellipsize="end"
            android:gravity="left|center_vertical"
            android:paddingBottom="10dp"
            android:paddingLeft="4dp"
            android:paddingRight="18dp"
            android:paddingTop="10dp"
            android:singleLine="true"
            android:textSize="17sp" &gt;
        &lt;/EditText&gt;
    &lt;/LinearLayout&gt;


&lt;/LinearLayout&gt;
</code></pre>

<p>This is the parent container</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_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp"
    style="@style/GroupedTextViewContainer" &gt;

    &lt;LinearLayout
        android:id="@+id/items_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/item_background"
            android:orientation="vertical" &gt;
    &lt;/LinearLayout&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p>This is how i use the layout </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="match_parent"
    android:orientation="vertical" &gt;

    &lt;com.myapp.ui.ContainerView
        android:id="@+id/cv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp" &gt;

        &lt;com.myapp.ui.MyFirstView
            android:id="@+id/abc"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" /&gt;

    &lt;/com.myapp.ui.ContainerView&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p>Now i want to basically add the MyFirstView into the items_container linear_layout. The parent of the items_container has a border around it so i want everthing added to the items container and then the items container added to the layout with the border around it.</p>

<p>Hope i make sense</p>

<p>Kind Regards.</p>
