I want to create a UI layout in XML and have it inserted as a child into an existing view (It will be inserted multiple times).
For example, here is what the XML file will contain:
Now I get the parent LinearLayout and now want to add that XML file as a child view, eg:
LinearLayout linear = (LinearLayout)findViewById(R.id.myLayout);
//need to create a view object from the xml file
Is it possible to convert an XML resource to a view type? If so, how would I do this?
I believe you want the LayoutInflater. Let's say your example XML is in a file
LayoutInflater inflater = LayoutInflater.from(context); RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.custom_layout, null, false); LinearLayout linear = (LinearLayout)findViewById(R.id.myLayout); linear.addView(layout);