Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to extend include tag on Android
    text
    copied!<p>I ended up having many xml files sharing the same code on the header and footer. Is there any good way to create some kind of template and to pass it a resource to include in the middle ?</p> <p>In other words, how to extend the Include tag in such a way I could, rather than simply include a view, include a template which includes the given resource ?</p> <p>My messy code:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;include layout="@layout/settings_section" /&gt; </code></pre> <p>settings_section.xml: </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;!--Header Begin--&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="10dp" &gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@layout/my_shape" android:orientation="vertical" &gt;&lt;include layout="@layout/header" /&gt; &lt;!--End header--&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" android:text="Blah blah blah" /&gt; &lt;!--Footer Begin --&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; &lt;!-- Footer End --&gt; </code></pre> <p>What I would like:</p> <pre><code>&lt;include layout="@layout/header" /&gt; &lt;com.example.Include layout="@layout/settings_section" inside="@layout/default_template" /&gt; </code></pre> <p><strong>EDIT</strong>: I'm looking for code samples.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload