I need to dynamically add a ‘template’ layout to my activity at runtime based on the click of a button.
Shown in the code block below is a simplified version of my layout. The contents of HEADER C (i.e. BODY C1, BODY C2 … BODY Cn) are the components that need to be added at runtime. They are all of the same format and are defined in a separate xml file with a relative layout. How do I accomplish this task? I have tried a LayoutInflater, but was unsuccessful. Does LayoutInflater require a LinearLayout to inflate?
<SCROLLVIEW>
<RELATIVE_LAYOUT>
____________
HEADER A
____________
BODY A
</RELATIVE_LAYOUT>
<RELATIVE_LAYOUT>
____________
HEADER B
____________
BODY B
</RELATIVE_LAYOUT>
<RELATIVE_LAYOUT>
____________
HEADER C
____________
BODY C1
____________
BODY C2
.
.
.
____________
BODY Cn
<RELATIVE_LAYOUT>
</SCROLLVIEW>
Thanks, any guidance is appreciated!
1 Answer