title: Reusing layout XML and the code behind
body: <p>I am trying to turn a couple buttons into a reusable component in Android.  I have successfully gotten the XML / UI portion working, but I can't figure out how to make code behind it reusable between activities, short of recoding it everywhere.  I am new to Android, so I apologize if this is obvious.</p>
  
  <p>I've already reviewed this post several times: <a href="http://www.curious-creature.org/2009/03/01/android-layout-tricks-3-optimize-part-1/comment-page-1/#comment-3863" rel="noreferrer">Android layout Tricks 3 - Part 1</a> but it seems to be missing a few files, and I do not have enough experience to rebuild them.</p>
  
  <p>A dumbed down version of my main layout:</p>
  
  <pre><code>  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
  
      &lt;WebView android:id="@+id/webview" 
          android:layout_width="fill_parent"
          android:layout_height="375px" 
          android:layout_alignParentTop="true" /&gt;
  
          &lt;include layout="@layout/navbar"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>and then of my "component":</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;merge xmlns:android="http://schemas.android.com/apk/res/android"&gt;
        &lt;LinearLayout   
              android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_alignParentBottom="true"
              android:gravity="center"&gt;
  
              &lt;ImageButton android:id="@+id/Button1" 
                  android:layout_width="71px"
                  android:layout_height="wrap_content"
                  android:background="@drawable/button1"              
                  android:layout_alignParentBottom="true" /&gt;
  
  
              &lt;ImageButton android:id="@+id/Button2" 
                  android:layout_width="75px"
                  android:layout_height="wrap_content"
                  android:background="@drawable/button1"  
                  android:layout_toRightOf = "@+id/Button1"
                  android:layout_alignParentBottom="true" /&gt;              
  
          &lt;/LinearLayout&gt;
          &lt;/merge&gt;
  </code></pre>
  
  <p>If you have any additional critiques on my XML, I would appreciate that too.</p>