Include objects from other layouts android
<p>I got a xml layout file like this:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
</code></pre>

<p></p>

<pre><code>&lt;LinearLayout
    android:id="@+id/tabBar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#474747"
    android:orientation="horizontal" &gt;

    &lt;ImageButton
        android:id="@+id/BtnSlide"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@null"
        android:src="@drawable/lin" /&gt;

    &lt;TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="SteriaFIT Mobile"
        android:gravity="center"
        android:paddingLeft="12dp"
        android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
&lt;/LinearLayout&gt;

&lt;RelativeLayout
android:background="#41413F"
android:layout_height="wrap_content"
android:layout_width="fill_parent"&gt;
    &lt;LinearLayout
        android:id="@+id/some_layout_item"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"&gt;

&lt;/LinearLayout&gt;

&lt;View
    android:layout_below="@id/some_layout_item"
    android:layout_width="fill_parent"
    android:layout_height="5dip"
    android:background="@drawable/drop_shadow"&gt;
&lt;/View&gt;
</code></pre>

<p></p>

<pre><code>&lt;ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content"
    android:background="#FFFFFF" android:cacheColorHint="#FFFFFF"&gt;
&lt;/ListView&gt;


&lt;Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="To Next Activity" /&gt;
</code></pre>

<p></p>

<p>I only want to get the <code>tabBar</code> layout from this file into another xml layout file, i do this by including after <code>@+id</code> this way:</p>

<pre><code>&lt;include android:id="@+id/tabBar" layout="@layout/horz_scroll_app" /&gt;
</code></pre>

<p>but it seems to me that this line of code will include the whole layout file?</p>

<p><strong>EDIT</strong></p>

<p>should mention that this method will also give me the <code>Button</code> with the id <code>button1</code></p>

<p><strong>EDIT 2</strong></p>

<p>Ok, so after putting the <code>tabBar</code> inside a new layout file like this:</p>

<pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/tabBar"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:background="#474747"
  android:orientation="horizontal" &gt;

    &lt;ImageButton
        android:id="@+id/BtnSlide"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@null"
        android:src="@drawable/lin" /&gt;

    &lt;TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="SteriaFIT Mobile"
        android:gravity="center"
        android:paddingLeft="12dp"
        android:textAppearance="?android:attr/textAppearanceMedium" /&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p>and included this to my orginal xml layout like this:</p>

<pre><code> &lt;include  layout="@layout/tab_bar" android:id="@+id/tabBar" /&gt;
</code></pre>

<p>it seems to me that I cant register any <code>OnClickListener</code> to my <code>ImageButton</code> inside my <code>tabBar</code> layout. What I tried to do:</p>

<pre><code> View app = inflater.inflate(R.layout.tab_bar, null);
 ViewGroup tabBar = (ViewGroup) app.findViewById(R.id.tabBar);

btnSlide = (ImageButton) tabBar.findViewById(R.id.BtnSlide);
btnSlide.setOnClickListener(new ClickListenerForScrolling(scrollView, menu));
</code></pre>

<p>Can anybody give me a hint= </p>
