Daniele Vitali
Daniele Vitali

Reputation: 3868

How to load a resource layout into the code

I have a linear layout, defined using xml. I would like to reuse it. Thus, I need to load it in the code. I have found getResoruces().getLayout(R.layout.my_layout) but it returns an XmlResourceParser object. How can I convert it into a Linear Layout, please?

Upvotes: 0

Views: 56

Answers (2)

chefburns
chefburns

Reputation: 407

Have a look at the LayoutInflator. It should do what you need.

Upvotes: 0

Sercan Ozdemir
Sercan Ozdemir

Reputation: 4691

Give an ID to your linearlayout from XML then use below code.

LinearLayout myLinLay=(LinearLayout)findViewById(R.id.my_layout);

Upvotes: 1

Related Questions