I have a layout in xml It contains also:

<RelativeLayout
    android:id="@+id/item"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
/>

I'd like to inflate this relative view with other xml layout file I might use different layouts depending on a situation How do i manage myself? I was trying different variations of

RelativeLayout item = (RelativeLayout) findViewById(R.id.item);
item.inflate(...)

But none of them had been good

Best Answer


I'm not sure i followed your question- are you trying to attach a child view to the relativelayout? If you want to do something in the same way

RelativeLayout item = (RelativeLayout)findViewById(R.id.item);
View child = getLayoutInflater().inflate(R.layout.child, null);
item.addView(child);