Inflating an XML Layout into a Custom ViewGroup

I am trying to inflate an XML layout into a custom one ViewGroup. After inflating the layout ViewGroupdisplays only the root view of the layout, it should display the full layout file in ViewGroup.

I looked at other similar issues related to this on stackoverflow and other sites, but none of them helped.

Here is my custom code ViewGroup:

public class ViewEvent extends ViewGroup {
private final String LOG_TAG="Month View Event";
public ViewEvent(Context context) {
        super(context); 
    }

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

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {      

        int childCount= getChildCount();
        for(int i=0;i<childCount;i++)
        {   
            Log.i(LOG_TAG, "Child: " + i + ", Layout [l,r,t,b]: " + l + "," + r + "," + t + "," + b);
            View v=getChildAt(i);
            if(v instanceof LinearLayout)
            {
                Log.i(LOG_TAG, "Event child count: " + ((ViewGroup)v).getChildCount()); // displaying the child count 1
                v.layout(0, 0, r-l, b-t);
            }
            //v.layout(l, r, t, b);
        }
    }   

In Activity, I use this custom view group:

ViewEvent event = new ViewEvent(getApplicationContext());
LayoutInflater inflator;
inflator=(LayoutInflater)appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflator.inflate(R.layout.try1, event);
setContentView(event);

The following is the layout file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="horizontal"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="#ffffaa77">


    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#ffff0000"
        android:text="asdasadfas" />

</LinearLayout>

After inflating this layout, I get only the root LinearLayoutwith the color backgroud #ffff0000. TextViewnot displayed.

Where am I mistaken or is something missing?

+5
2

getParent() ( ViewEvent):

inflator.inflate(R.layout.try1, event.getParent(), false);
+2

. - TextView.

   <TextView 
            android:id="@+id/testTextId"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#ffff0000"
            android:text="asdasadfas" />

TextView, .

TextView testTextView = (TextView) ViewEvent.findViewById(R.id.testTextId);
-1

All Articles