Comet
Comet

Reputation: 163

How to add child layouts in a Custom built layout in android

I have created some xml layouts. Now I am creating a custom layout (in my java file) with some elements and want to add the previously created layout(xml layouts). How can I do that?

Upvotes: 1

Views: 359

Answers (2)

Ron
Ron

Reputation: 24233

Use <include> tag in your new layout. See docs here.

Upvotes: 0

Murat Nafiz
Murat Nafiz

Reputation: 1438

You can use LayoutInflater to inlate layouts. And add inflated view to your custom view by addView() method

For ex:

LayoutInflater mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewGroup viewTobeLoaded = mInflater.inflate(R.layout.ilan_list_item, null);
yourView.addView(viewTobeLoaded);

Hope helps

Upvotes: 2

Related Questions