Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import xml into another xml

Tags:

android

xml

I have lots of control repeated in my xml (a Button for instance). Is there any possibility to write the Button once in a xml and then import it in all the layout I need it?

like image 721
Blackbelt Avatar asked Nov 09 '10 09:11

Blackbelt


People also ask

Can I import one XML into another XML?

An XML external entity cannot be a full-blown independent XML document—neither standalone XML declaration nor Doctype declaration is allowed. That effectively means an XML external entity itself cannot include other external entities.

How do I insert one XML file into another Android?

Probably you will have to set within the include tag the properties that sets where it has to be placed: android:layout_above, android:layout_toLeftOf, etc... Use fill_parent instead. I pasted my code and I am working with honeycomb, thats why I was using match_parent. But it should work with fill_parent.

What happens if you import XML data without a schema?

If you import XML data without first adding a corresponding XML schema to create an XML map, Excel tries to infer a schema for you based on the tags that are defined in the XML data file.


2 Answers

You can use

<include  layout="@layout/commonlayout" android:id="@+id/id" /> 

commonlayout.xml should be defined in res/layout where you can add the repeated parts.

like image 181
Labeeb Panampullan Avatar answered Sep 22 '22 17:09

Labeeb Panampullan


As Labeeb P rightly said, it works. Just want to add that you can also override parameters too:

<include           layout="@layout/commonlayout"          android:id="@+id/id"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_weight="1"         android:layout_marginLeft="2sp"         android:layout_marginRight="2sp"  /> 
like image 25
TsimoX Avatar answered Sep 19 '22 17:09

TsimoX